Help coderanch get a
new server
by contributing to the fundraiser
  • 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Read a file from a mapped drive

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to read a file from a mapped drive using a servlet. I used the following code to map the drive:
try{
Runtime.getRuntime().exec("net use x: \\\\servername\\dir");
}
catch(IOException ioe) {
... set error
return;
}
which when I run this it doesn't throw an ioexception. But when I try to read a file using the following code:
File dir = new File("x:\\version.dat");
FileInputStream in = new FileInputStream(dir);
int c;
while ((c = in.read()) != -1)
inBuf.append((char)c);
in.close();

I get this error:
reported this exception: x:\version.dat (The system cannot find the path specified). Please report this to the administrator of the web server.
java.io.FileNotFoundException: x:\version.dat (The system cannot find the path specified) at java.io.FileInputStream.open(Native Method) ........
I even logged onto the server and mapped x: from the command prompt and then verified with dir that the file was there. Does anyone have any ideas on how to make this work or if I have the directory mapped correctly?
 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have run into the same problem. Can anybody help?
 
We can fix it! We just need some baling wire, some WD-40, a bit of duct tape and this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic