I have a Java application were the user can create a text file and save it wherever he wants on his computer using this code :
File txtFile = new File( path );
Writer writer = new BufferedWriter( new OutputStreamWriter( new FileOutputStream( txtFile ), "UTF-8" ) ); // Error occurs here.
But many users using Windows 7 reported that when saving the file to "C:\", they get "Access is denied" error. I found that this is because they need administrator permissions to save the file in such path in Win7.
Instead of showing a warning message to the user: " You can't save the file at this path ", can i save the file in this path somehow, like if there is a way to have Administrator permissions in Win7 through Java code, or something like that ?
解决方案
Short answer - no.
If you need to save to C drive, they need permissions. If this program just needs to create files, you can use the users temp folder. See System.getProperty()