0

I need to read/write on client machine. I followed this post and successfully got it to the point where the "Security Warning" message appears. But when I am making the call to Applet method from Javascript, I am getting the file permission error. I do not want to use Java Policy and use only signed applet. Is there any thing else required? I not very good at core Java and need some directions. Applet Code:

public class FileIo extends JApplet {
    public void init(){
    }
    public static void main(String[] args) throws IOException {
        FileIo obj = new FileIo();
        obj.ReadFile(args[0]);
    }
    public String ReadFile(String fn) {
        String thisLine, ret="";
        try{
            FileInputStream fin =  new FileInputStream(fn);
            BufferedReader myInput = new BufferedReader(new InputStreamReader(fin));
            while ((thisLine = myInput.readLine()) != null) {  
                ret += thisLine + "\n";
            }
        }
        catch(Exception e) {
            ret = e.toString();
        }
        System.out.println(ret);
        return ret;
    }
}

HTML where Applet is added:

<script>
    var attributes = {id: 'FileIoApplet',
         codebase: '/webapp',
                      code: 'FileIo.class',
                      archive: 'FileIo.jar'};
    var parameters = {java_arguments: '-Xmx256m'};
    var version = '1.8'; // JDK version
    deployJava.runApplet(attributes, parameters, version);
</script>

Javascript Call to Applet method:

alert(FileIoApplet.ReadFile('c:\\data\\info.txt'));

Following is the error that I get:

enter image description here

FaisalKhan
  • 2,406
  • 3
  • 25
  • 32
  • This is a bit tangential to your question, but be aware that browser vendors are actively removing support for the Java plugin from their browsers. Chrome on \*nix already doesn't have it, Chrome on Windows won't have it in a couple of months (unless they push that back again), Mozilla has said they'll be getting rid of it... The writing is very clearly on the wall. – T.J. Crowder Aug 15 '15 at 14:04
  • Thanks @T.J.Crowder . I am also not very happy with the solution but need to store some data on client machine. Local Storage is one option but I don't want to rely on it primarily because localcache can be cleared and everything goes away for good. Do you have any suggestions. The problem is: One of the users of my app is not willing to store some data on the cloud and I came up with this solution. Any tips??? Thanks. – FaisalKhan Aug 15 '15 at 14:22
  • I would use local storage and tell the users that clearing it will lose their data. :-) And offer them a way to downoad it (e.g., by clicking a link) and upload it (via file input, either file upload or reading the file using the File API), so they can do backups. – T.J. Crowder Aug 15 '15 at 14:33
  • 1
    Thanks @T.J.Crowder. I was trying to make all this seamless that will not have any user action. Considering the way internet is going ahead, the users will have to live with some manual actions. I was actually avoiding the user intervention but it seems inevitable now. Thanks for your input and time. Cheers :) – FaisalKhan Aug 15 '15 at 14:49

0 Answers0