Win a copy of Terraform in Action this week in the Cloud forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

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

 
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic