Forums Register Login

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

+Pie Number of slices to send: Send
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)

1
+Pie Number of slices to send: Send
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.



+Pie Number of slices to send: Send
Yes, I did that and it works. Is there a way of making our code "create new files/folders as an administrator" ?

Thanks
1
+Pie Number of slices to send: Send
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 . . .
+Pie Number of slices to send: Send
 

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.
+Pie Number of slices to send: Send
When you have worked out how to do it, please tell this chap how to get accepted by a firewall, too
Dinner will be steamed monkey heads with a side of tiny ads.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 32346 times.
Similar Threads
Tomcat4.1.24 not working as a NT service??
Unable to Create Non-Read-Only Directories...
How to convert Blob Type back to File
tomcat log file!!
copy files from one folder to another in java
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 05:11:36.