Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jan 2004
    Posts
    61
    Thanks
    0
    Thanked 0 Times in 0 Posts

    JAVA Applet: write to file

    Code:
    import java.io.*;
    
    public class WriteIt {
      public boolean writeFile(String text, String fileID) {
        try {
          File file = new File(fileID);
          FileWriter fWriter = new FileWriter(file);
          fWriter.write(text);
          fWriter.close();
          return true;
        } catch(IOException e) {
          return false;
        }
      }
    }
    Welcome to DrJava.
    > WriteIt a = new WriteIt();

    > a.writeFile("AAAAAAAAAAAAXXX","C:\\folder 1\\x x\\dfjs.txt")

    true

    > a.writeFile("AAAAAAAAAAAAXXX","C:\\Documents and Settings\\Admin\\Desktop\\dfjs.txt")

    true

    > a.writeFile("AAAAAAAAAAAAXXX","dfjs.txt")

    The above class works fine, and that is what I expected.

    Should these to work for JApplet too? sinc I call these to write it to my "C:\\folder 1\\a.txt" for testing. no success

    any help?

  • #2
    Regular Coder
    Join Date
    Dec 2003
    Posts
    367
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Writing to the local file system would be a violation of the applet's security model. You might be able to accomplish it with a signed applet. But you're better off just saving the file on the server.

    shmoove

  • #3
    New Coder
    Join Date
    Jan 2004
    Posts
    61
    Thanks
    0
    Thanked 0 Times in 0 Posts
    how do a signed the applet?

    If we have a web server, we can run servlet for free?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •