473,409 Members | 1,945 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,409 software developers and data experts.

Saving file into local disc using Applet

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:

Expand|Select|Wrap|Line Numbers
  1. public class IO extends Applet {
  2.  
  3.     public void write(String path, String data) {
  4.         try {
  5.             File file = new File(path);
  6.             DataOutputStream dos = new DataOutputStream(
  7.                 new BufferedOutputStream(
  8.                     new FileOutputStream(file)));
  9.             dos.writeBytes(data);
  10.             dos.close();                    
  11.         }
  12.         catch (SecurityException se) {
  13.             System.err.println(se.getMessage());
  14.         }
  15.         catch (IOException ioe) {
  16.             System.err.println(ioe.getMessage());
  17.         }
  18.     }
  19.  
  20.     public void paint(Graphics g) {
  21.     }
  22.  
  23. }
Html sample file:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <applet archive="IO.jar" code="IO.class" name="io" width="0" height="0"></applet>
  3. <script type="text/javascript">
  4. function saveText() {
  5.     document.applets[0].write("c:\\test.txt", "Hello World!");
  6. }
  7. saveText();
  8. </script>
  9. </html>
May 25 '09 #1
5 6406
JosAH
11,448 Expert 8TB
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
May 25 '09 #2
@JosAH
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
Jul 2 '09 #3
JosAH
11,448 Expert 8TB
@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
Jul 3 '09 #4
@JosAH
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 ;-).
Jul 6 '09 #5
JosAH
11,448 Expert 8TB
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
Jul 6 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Jan Meyer | last post by:
Where (aka what directory) do you put a java.policy file on a website for a particular applet??? There are presently no java.policy files on the web server. tia
1
by: Georg Andersson | last post by:
hi is it posslible to enable an applet to write data to the server, where the applet itself is located? how would in this case the entry in the policy-file on the server look like? tx for...
13
by: John Howard | last post by:
I have the following in a jythonc program to be executed in a html file. f1 = open("filename","r") I get message about filePermission read error. Program compiles and jar file is created....
1
by: ramon | last post by:
Hi! I have a fairly complex object (with other objects as attributes (which in turn, have other objects as attributes), methods, etc) and I would like to save it to the disc so I can load it in...
0
by: edJames | last post by:
Hi Im writing a java applet that calls a perl script to save pictures generated by the applet locally. The applet converts the onscreen buffer into a GIF and sends in via POST in a byte stream....
2
by: plank | last post by:
Hey Peeps, Ok here is my situation.. I have a Java applet which allows the user to select files and upload them to the server. The applet converts the file to Base64 and then POSTS the data to an...
1
by: tarepanda | last post by:
Hi, I'm really clueless on where my code goes wrong in Firefox. Mine is version 2.0.0.6. I have a signed applet that allows for recording, playing back and saving of audio files. The interface...
3
by: =?Utf-8?B?YzY3NjIyOA==?= | last post by:
Hi all, I cut and paste the following code from msdn help page which it just introduces view and multiview server controls. Here is what I do: in vs studio 2005, File --New Web Site, it...
2
by: JohnLorac | last post by:
Hello, I'm trying to load and write file on local disc drive using signed javascript file. But I have experienced problem running this url: ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.