Saving file into local disc using Applet 
May 25th, 2009, 02:26 PM
| | Newbie | | Join Date: Apr 2009
Posts: 5
| |
Hello,
can somebody help me with saving file into local disk
using javascript? I made some sample code which
unfortunately won't work :(.
Applet sample file: - public class IO extends Applet {
-
-
public void write(String path, String data) {
-
try {
-
File file = new File(path);
-
DataOutputStream dos = new DataOutputStream(
-
new BufferedOutputStream(
-
new FileOutputStream(file)));
-
dos.writeBytes(data);
-
dos.close();
-
}
-
catch (SecurityException se) {
-
System.err.println(se.getMessage());
-
}
-
catch (IOException ioe) {
-
System.err.println(ioe.getMessage());
-
}
-
}
-
-
public void paint(Graphics g) {
-
}
-
-
}
Html sample file: - <html>
-
<applet archive="IO.jar" code="IO.class" name="io" width="0" height="0"></applet>
-
<script type="text/javascript">
-
function saveText() {
-
document.applets[0].write("c:\\test.txt", "Hello World!");
-
}
-
saveText();
-
</script>
-
</html>
| 
May 25th, 2009, 02:33 PM
|  | Expert | | Join Date: Mar 2007
Posts: 10,634
Provided Answers: 2 | | | re: Saving file into local disc using Applet
What does "doesn't work" mean? Did you get a Permissions exception? If so, there's another thread going on in this forum about the very same subject; you have to make your Applet 'trusted' then by fiddling with a policy file telling the SecurityManager that such an action (writing a file) is an allowed action.
kind regards,
Jos
| 
July 2nd, 2009, 07:50 PM
| | Newbie | | Join Date: Apr 2009
Posts: 5
| | | re: Saving file into local disc using Applet Quote:
Originally Posted by JosAH What does "doesn't work" mean? Did you get a Permissions exception? If so, there's another thread going on in this forum about the very same subject; you have to make your Applet 'trusted' then by fiddling with a policy file telling the SecurityManager that such an action (writing a file) is an allowed action.
kind regards,
Jos | Yes, I got permission exception. But I don't care about this anymore. Finally I found solution! Watch this video here on youtube: http://www.youtube.com/watch?v=wqpwyAAhKGg | 
July 3rd, 2009, 02:41 PM
|  | Expert | | Join Date: Mar 2007
Posts: 10,634
Provided Answers: 2 | | | re: Saving file into local disc using Applet Quote:
Originally Posted by JohnLorac | Care to explain how it works? I saw an IO.jar in the text; what code does it contain in its class(es)?
kind regards,
Jos
| 
July 6th, 2009, 01:03 PM
| | Newbie | | Join Date: Apr 2009
Posts: 5
| | | re: Saving file into local disc using Applet Quote:
Originally Posted by JosAH Care to explain how it works? I saw an IO.jar in the text; what code does it contain in its class(es)?
kind regards,
Jos | Hello, IO.jar contains signed Java class with five basic methods (write, read, remove, exists and browse) for manipulating with files on local hard disc. There isn't big deal to manage this with signed applet. Everyone can do. There is plenty tutorials how to do this. But, when you want to do the same thing with JavaScript interface then you found there is plenty of problems how to manage cooperation between JavaScript and Java to works together correctly. This solution simply solve this problems ;-).
| 
July 6th, 2009, 02:48 PM
|  | Expert | | Join Date: Mar 2007
Posts: 10,634
Provided Answers: 2 | | | re: Saving file into local disc using Applet
Ah, ok, you still need to use a signed applet; I wondered if you found a tricky way to accomplish the same without a trusted applet' thanks for the reply.
kind regards,
Jos
|  |
Similar Threads | | Thread | Thread Starter | Forum | Replies | Last Post | | Java and PHP | Georg Andersson | answers | 2 | July 18th, 2005 12:30 AM | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 225,662 network members.
|