File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.io.FileNotFoundException: C:\textfile.txt (Access is denied)

 
justin smythhe
Ranch Hand
Posts: 107
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why is access denied ??? I suspect this is a Windows 7 security related problem. How do i solve this problem ?

java.io.IOException: Access is denied
Caught exception - Cannot create your file !!!
java.io.FileNotFoundException: C:\textfile.txt (Access is denied)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:180)
at java.io.FileOutputStream.<init>(FileOutputStream.java:122)
at java.io.FileWriter.<init>(FileWriter.java:62)

 
Paul Adcock
Ranch Hand
Posts: 48
Firefox Browser Java Notepad
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I found the problem. I checked by trying to save a text file right to that location manually and got a "you don't have permission error".

You can't save directly to the C drive like that I think.

Normally, since most Computers have a Users directory underneath the C drive, yours might not but the chances are high that it does,

then you would make a new Directory under the users directory, you might be able to just create it programmatically.


Anyway,

try creating it as C:/Users/SomeDirectory/textfile.txt


At the very least, you need a subdirectory underneath C. You can't just save something as a file itself to the C drive itself.

Sorry, scratch that, normally under the Users directory, you have a directoy that is your computer name. I wouldn't know what yours is.

so it's

C:/Users/YourComputerName/textfile.txt

that will work.



 
justin smythhe
Ranch Hand
Posts: 107
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I did that and it works. Is there a way of making our code "create new files/folders as an administrator" ?

Thanks
 
Campbell Ritchie
Sheriff
Pie
Posts: 47313
52
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you actually want code running on your computer in administrator mode? It is all right if you write it yourself, but what if somebody else wrote it . . .
 
justin smythhe
Ranch Hand
Posts: 107
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Do you actually want code running on your computer in administrator mode? It is all right if you write it yourself, but what if somebody else wrote it . . .

Oh ! yes.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47313
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you have worked out how to do it, please tell this chap how to get accepted by a firewall, too
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic