I have some questions about your post, it's not very clear to me:
a) what has you post to do with your subject line (file permissions) ?
b) why are there two applets. the question has nothing to do with both applets
c) your question has nothing to do with the fact, that both applets are called simultaneously.
d) why do you want to stop the user from editing a text field? just remove the text field from the applet, and the user won't be able to edit it any more....
okay, perhaps you wanted to know, if it is possible, that Applet A can control Applet B in such a way, that if something happens, the textfield in Applet B gets disabled (remotely by Applet A) ?
you can get a list of all running applets on the same website with the following code:
Enumeration applets = this.getAppletContext().getApplets();
while(applets.hasMoreElements()) {
Applet otherApplet = (Applet) applets.nextElement();
// now you can control the other applet
}
use this in Applet A to get Applet B. once you have found Applet B, you can call a method , something like disableTextfield().
To disable a textfield, use this:
TextField username = new TextField();
username.setEditable(false);
sorry, but i really don't understand you.
do you mean this:?
grant codeBase "http://url.to/your/applet.jar" {
permission java.security.AllPermission;
permission java.io.FilePermission "autoexec.bat", "read";
};
or do you want to change the file attributes (read-only, system file, hidden) of the file? ("make the file read-only")
please, please, please be MORE INFORMATIVE.
your posts are very hard to understand, in fact, not understandable.
at first, you are talking about a text field, which you want to be read-only.
then, it's the policy file. and after that, it's a file attribute in the file system.
then, it's the policy file again.
you will explain all that to me with at least 200 words, otherwise i won't answer.
Hi,
Here is what I would like to do.Please revert back the part you dont understand
1.The applet has an option to open the file and read its contents.
2.It may be any file which is readable in the notepad.
3.I want the end user to stop writing anything on it.
4.When he writes anything on it then it should throw a security exception in the command prompt.
5.With the .java.policy file can this be done?
6.If know then please tell other methods?
7. I want the command prompt to throw an security exception when something is done?
ThankYou.Please revert back if you have any clarifications in this regard and the portion of the mail you dont understand.
you tried the setReadOnly() method and it didn't work?
i don't think the java.policy file will work, because it seems that you want to change the behaviour while the program is running?
you are writing that you have an applet. the user starts the applet. when he can use the applet to change the contents of a text file (files which can be opened in notepad?)
if some event occurs, you want to stop editing, so the user can't edit any more. you want that a security exception is thrown.
you can throw your own security exception with "throw <ExceptionName>"
Hi Experts, I need to know how to make a read-only file writable. The File class has a method to find out if a file is read-only and a method to set a file read-only called setReadOnly(), but not a method to set a file not read-only; i.e. setNotReadOnly(). Does anyone know a way to make files not read-only/writable?
Regards,
Deepali
Hi People,
I have found a solution, I am not sure if its the best one but just thought of post FYI.
Process p = Runtime.getRuntime().exec("C:\\WINDOWS\\system32\\attrib -r " + filename);
This did the trick. Please let me knwo if anybody has a better solution.
Regards,
Deepali
> Hi People,
>
> I have found a solution, I am not sure if its the
> best one but just thought of post FYI.
>
> Process p =
> Runtime.getRuntime().exec("C:\\WINDOWS\\system32\\attr
> ib -r " + filename);
>
> This did the trick. Please let me knwo if anybody has
> a better solution.
>
> Regards,
> Deepali
IO API doesn't allow to make file writable that is currently read only.
I would prefer to delete the file and write it again.
This seems portable solution though ugly.