Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
191 views
in Technique[技术] by (71.8m points)

java - Creating file on Windows 7 causes "Access denied" exception

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 ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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()


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.9k users

...