aspose file tools*
The moose likes Beginning Java and the fly likes java.io.FileNotFoundException: C:\textfile.txt (Access is denied) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "java.io.FileNotFoundException: C:\textfile.txt (Access is denied)" Watch "java.io.FileNotFoundException: C:\textfile.txt (Access is denied)" New topic
Author

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

justin smythhe
Ranch Hand

Joined: Jul 06, 2012
Posts: 107
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

Joined: Jan 22, 2011
Posts: 48

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.




Repeal Obamacare.
http://www.dontfundobamacare.com/
http://liberty-amendments.freeforums.net/
justin smythhe
Ranch Hand

Joined: Jul 06, 2012
Posts: 107
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

Joined: Oct 13, 2005
Posts: 40059
    
  28
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

Joined: Jul 06, 2012
Posts: 107
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

Joined: Oct 13, 2005
Posts: 40059
    
  28
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
 
subject: java.io.FileNotFoundException: C:\textfile.txt (Access is denied)