Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Access is denied i/o exception when trying to write a file.  RSS feed

 
Kim Kantola
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gang,
I am getting the following exception when I try to write a file to another machine on my network. I am using Windows 2K.
This code works fine when I copy a file from one directory to another on my own machine, but when I try to write to another machine on the network I get an "access is denied exception:
(Note: I overwrote the actuall IP address of the path in the exception message and the code with the text "IPAddress" for privacy)
The exception:
java.io.FileNotFoundException: \\IPAddress\d\tng2.0\config\ex.properties (Access is denied)
at java.io.FileOutputStream.open(Native Method) at java.io.FileOutputStream.<init>(FileOutputStream.java:102)
The Code:
/**
* Copy file to store machines
*/
public void copyFile(String _filePath) throws IOException {
File inputFile = new File(_filePath);
File outputFile = new File("\\\\IPAddress\\c\\tng2.0\\config\\exit41.properties");
FileReader in = new FileReader(inputFile);
FileWriter out = new FileWriter(outputFile);
int c;
while ((c = in.read()) != -1)
out.write(c);
in.close();
out.close();
}
Any info would be greatly appreciated to help me get past this exception!
Thanks very much,
Kim
 
Kim Kantola
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, me again,
I just tried adding this line to my code:
FilePermission permission = new FilePermission("\\\\IPAddress\\C\\tng2.0\\config\\*", "read,write");
Still getting the same Access is Denied exception.
Think I am on the right path with the FilePermission object?
Kim
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!