The moose likes I/O and Streams and the fly likes Read a file from a mapped drive Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Reply Bookmark "Read a file from a mapped drive" Watch "Read a file from a mapped drive" New topic
Author

Read a file from a mapped drive

Chris Behr
Greenhorn

Joined: Jun 12, 2001
Posts: 17
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?
Sunetra Saha
Ranch Hand

Joined: Feb 25, 2001
Posts: 77
I have run into the same problem. Can anybody help?
 
 
subject: Read a file from a mapped drive
 
Threads others viewed
Re: Attach is the detail on the servlet error "The system cannot find the path specified"
Relative path of file in FileInputStream
System cannot find the path specified
File Not Found Path Problem in JSP
Servlet Error : The system cannot find the path specified
IntelliJ Java IDE