Add what to the applet?
How can the applet carry its permissions with it? Wouldn't that make security useless?
The .java.policy file is used by the java program to grant permissions to applets.
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
Add what to the applet?
How can the applet carry its permissions with it? Wouldn't that make security useless?
The .java.policy file is used by the java program to grant permissions to applets.
If you don't understand my answer, don't ignore it, ask a question.
How do you do that?
Where is the user dir?
Do you have to have every computer to have that file?
Google .java.policy and read the doc all about it.
Correction: the file is in the user.home folder. Use this to find it:System.out.println(System.getProperties().getProperty("user.home"));
If you don't understand my answer, don't ignore it, ask a question.
I didn't find it in there?
What is the "it" that you did not find?
If you don't understand my answer, don't ignore it, ask a question.
I couldn't find the .java.policy file.
There isn't one until you create it. Use the policytool program to create one and save it to the user.home folder.
If you don't understand my answer, don't ignore it, ask a question.
ajayajayaj (February 22nd, 2013)
I did the all permissions.
But now I get the error:
Java Plug-in 10.15.2.03
Using JRE version 1.7.0_15-b03 Java HotSpot(TM) Client VM
User home directory = C:\Users\Ajay
----------------------------------------------------
c: clear console window
f: finalize objects on finalization queue
g: garbage collect
h: display this help message
l: dump classloader list
m: print memory usage
o: trigger logging
q: hide console
r: reload policy configuration
s: dump system and deployment properties
t: dump thread list
v: dump thread stack
x: clear classloader cache
0-5: set trace level to <n>
----------------------------------------------------
C:\Users\Ajay
Exception in thread "AWT-EventQueue-2" java.lang.RuntimeException: could not rename the file C:\users\Ajay\AppData\test\test.zip to C:\Users\Ajay\AppData\Local\Temp\test5089272292711 443389.tmp
at Main.run(Main.java:131)
at Main.paint(Main.java:59)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JLayeredPane.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paintToOffscreen(Unknown Source)
at javax.swing.RepaintManager$PaintManager.paintDoubl eBuffered(Unknown Source)
at javax.swing.RepaintManager$PaintManager.paint(Unkn own Source)
at javax.swing.RepaintManager.paint(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at java.awt.GraphicsCallback$PaintCallback.run(Unknow n Source)
at sun.awt.SunGraphicsCallback.runOneComponent(Unknow n Source)
at sun.awt.SunGraphicsCallback.runComponents(Unknown Source)
at java.awt.Container.paint(Unknown Source)
at javax.swing.RepaintManager$3.run(Unknown Source)
at javax.swing.RepaintManager$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPri vilege(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unkno wn Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unkno wn Source)
at javax.swing.RepaintManager.prePaintDirtyRegions(Un known Source)
at javax.swing.RepaintManager.access$1000(Unknown Source)
at javax.swing.RepaintManager$ProcessingRunnable.run( Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPri vilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilter s(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Repeats...
Not sure that error has anything to do with the code being in an applet.java.lang.RuntimeException: could not rename the file C:\users\Ajay\AppData\test\test.zip to C:\Users\Ajay\AppData\Local\Temp\test5089272292711 443389.tmp
Try writing a small simple app with the code that created the error.
Why would there be a problem renaming a file?
If you don't understand my answer, don't ignore it, ask a question.
Oh sorry, I moved the file from the folder instead of copying it.
Now it says the original error:
Java Plug-in 10.15.2.03
Using JRE version 1.7.0_15-b03 Java HotSpot(TM) Client VM
User home directory = C:\Users\Ajay
----------------------------------------------------
c: clear console window
f: finalize objects on finalization queue
g: garbage collect
h: display this help message
l: dump classloader list
m: print memory usage
o: trigger logging
q: hide console
r: reload policy configuration
s: dump system and deployment properties
t: dump thread list
v: dump thread stack
x: clear classloader cache
0-5: set trace level to <n>
----------------------------------------------------
C:\Users\Ajay
java.io.FileNotFoundException: C:\users\Ajay\AppData\test\test.zip(Access is denied)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
at UnZipper.extract(UnZipper.java:35)
at Main.run(Main.java:175)
at Main.paint(Main.java:59)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JLayeredPane.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paintToOffscreen(Unknown Source)
at javax.swing.RepaintManager$PaintManager.paintDoubl eBuffered(Unknown Source)
at javax.swing.RepaintManager$PaintManager.paint(Unkn own Source)
at javax.swing.RepaintManager.paint(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at java.awt.GraphicsCallback$PaintCallback.run(Unknow n Source)
at sun.awt.SunGraphicsCallback.runOneComponent(Unknow n Source)
at sun.awt.SunGraphicsCallback.runComponents(Unknown Source)
at java.awt.Container.paint(Unknown Source)
at javax.swing.RepaintManager$3.run(Unknown Source)
at javax.swing.RepaintManager$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPri vilege(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unkno wn Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unkno wn Source)
at javax.swing.RepaintManager.prePaintDirtyRegions(Un known Source)
at javax.swing.RepaintManager.access$1000(Unknown Source)
at javax.swing.RepaintManager$ProcessingRunnable.run( Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPri vilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilter s(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Repeats...
I don't see anything about permission. Try the code in an app to see what happens there.
If you don't understand my answer, don't ignore it, ask a question.
Does trying the code in an app mean making a second applet with just hat code?
By app I mean a program that is executed using the java command and that executes without requiring permissions. Code that is not an applet.
If you don't understand my answer, don't ignore it, ask a question.
I get the same error!
java.io.FileNotFoundException: C:\users\Ajay\AppData\test\test.zip (Access is denied)
What is there about that file, its state and the OS that would cause the error?
Can you make a small simple program that compiles, executes and shows the problem for testing?
If you don't understand my answer, don't ignore it, ask a question.
For testing purposes, I tried accessing many directories.
When I even tried just accessing C:\users\<user>\Desktop\ it wouldn't work!
Sorry, I don't know what problems the OS can cause when accessing different folders.
If the program works with some files and folders and not others, then the OS could be causing the problem.
If you don't understand my answer, don't ignore it, ask a question.
For some unknown reason, now, I can't access any directory.
But only with that command.
I'm using:
try { FileOutputStream out = new FileOutputStream(new File("C:\\users\\Ajay\\desktop\\")); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); }
Last edited by Norm; February 23rd, 2013 at 03:34 PM. Reason: replaced quote with code tags
Please post a complete program that compiles, executes and shows the problem for testing.
Does that file path exist?
What error message do you get with the code in post#43?
If you don't understand my answer, don't ignore it, ask a question.
Yes it does exist.
The error message is:
java.io.FileNotFoundException: C:\users\Ajay\Desktop (Access is denied)
--- Update ---
What do you mean by:
Please post a complete program that compiles, executes and shows the problem for testing.
I changed the path to my desktop and get the same error now.
See post#42
If you don't understand my answer, don't ignore it, ask a question.
Here is the complete program that compiles, executes and shows the problem for testing:
public class TestProgram{ public static void main(String args[]){ try { FileOutputStream test = new FileOutputStream(new File("C:\\users\\" + System.getProperty("user.name"))); System.out.println("Success"); } catch (FileNotFoundException e) { e.printStackTrace(); } } }
I think that is controlled by the OS. Nothing to do with java.
If you don't understand my answer, don't ignore it, ask a question.
I can't find any real reasons why it does that.
--- Update ---
Do you know any way I could run this differently?
If it works for all folders except the desktop, then check the OS's settings for the reason.
This code works:try { File fo = new File("C:/users/" + System.getProperty("user.name") + "/Testfile"); System.out.println("fo="+fo); FileOutputStream test = new FileOutputStream(fo); System.out.println("Success"); } catch (FileNotFoundException e) { e.printStackTrace(); }
If you don't understand my answer, don't ignore it, ask a question.