Java Web Start Application can read files from local systems, but not write [closed]

最后都变了- 提交于 2019-12-22 11:29:05

问题


please ask if you need more info. I have the security and all permissions tags in my jnlp, and when I run my java app offline it works correctly.

File T = new File(System.getProperty("user.home") + File.separator + ".myapp/");<br />
if(!T.exists())
    T.mkdirs();
File[] temp=new File[2];

temp[0] = new File(System.getProperty("user.home") + File.separator +
                   ".myapp"+File.separator+"temp1.txt");
temp[1] = new File(System.getProperty("user.home") + File.separator +
                   ".myapp"+File.separator+"temp2.txt");

writer=new BufferedWriter(new FileWriter(temp[x]));
writer.write(finalData);
writer.close();

I use the following method to write to files I want to create in a directory in the user's system. In the program, I also read from the same folder and when I place test data in that folder it works correctly. When I remove the temp1.txt and temp2.txt files it does not read any data. No error messages come up or anything.

To reiterate, when ran in java web start, the window pops up and the program runs correctly with no error messages, but it does not write the files properly to the users system. At the same time, when test data is provided in .txt files, it reads it correctly.

Edit: If it is at all possible, could there be a solution without using some of the javaw.jnlp.* methods? The program really has to have a folder with .txt files to read from

edit2: All my jars are signed as well


回答1:


Can you try creating the file, before using it?.

temp[1].createNewFile()

This will create the file only if it doesn't exist. You can use return boolean flag to find out if the file already exists. This method will also throw an IOException if the security manager denies the create request.

EDIT:

According to java.io.FileWriter, file creation depends upon the underlying platform. Since you are able to read the file if it exists and only having problem with creating a new file in a JNLP app. I suggested creating a new file using createNewFile instead of relying on FileWriter to create the file.

From java.io.FileWriter javadoc:

Whether or not a file is available or may be created depends upon the underlying platform.




回答2:


Sorry guys, I was an idiot. My jnlp file pointed to a different version of my java program in my local system and basically I'm an idiot. When I went home, I tested the website from my home pc and found my error.

Thanks so much for your help though!



来源:https://stackoverflow.com/questions/11215311/java-web-start-application-can-read-files-from-local-systems-but-not-write

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!