File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Accessing File from other computer in network Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Accessing File from other computer in network" Watch "Accessing File from other computer in network" New topic
Author

Accessing File from other computer in network

Jonk kulsh
Greenhorn

Joined: Feb 04, 2005
Posts: 7
I'm getting problem in accessing file from other computer in the network. computer drive is shareble.



import java.io.FileReader;
import java.io.FileWriter;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.io.IOException;

public class ReadWriteTextFile {

private static void doReadWriteTextFile() {

try {

// input/output file names
String inputFileName = "\\192.165.0.5\\C:\\demo.java";
String outputFileName = "C:\\Demo\\demo1.java";

// Create FileReader Object
FileReader inputFileReader = new FileReader(inputFileName);
FileWriter outputFileReader = new FileWriter(outputFileName);

// Create Buffered/PrintWriter Objects
BufferedReader inputStream = new BufferedReader(inputFileReader);
PrintWriter outputStream = new PrintWriter(outputFileReader);

// Keep in mind that all of the above statements can be combined
// into the following:
//BufferedReader inputStream = new BufferedReader(new FileReader("README_InputFile.txt"));
//PrintWriter outputStream = new PrintWriter(new FileWriter("ReadWriteTextFile.out"));

outputStream.println("+---------- Testing output to a file ----------+");
outputStream.println();

String inLine = null;

while ((inLine = inputStream.readLine()) != null) {
outputStream.println(inLine);
}

outputStream.println();
outputStream.println("+---------- Testing output to a file ----------+");

outputStream.close();
inputStream.close();

} catch (IOException e) {

System.out.println("IOException:");
e.printStackTrace();

}

}


public static void main(String[] args) {
doReadWriteTextFile();
}

}


----------------------------------------------
Error i'm getting
----------------------------------------------

IOException:
java.io.FileNotFoundException: \192.165.0.5\C:\demo.java (The filename, director
y name, or volume label syntax is incorrect)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.io.FileInputStream.<init>(FileInputStream.java:66)
at java.io.FileReader.<init>(FileReader.java:41)
at ReadWriteTextFile.doReadWriteTextFile(ReadWriteTextFile.java:19)
at ReadWriteTextFile.main(ReadWriteTextFile.java:57)
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
In ...


... you needed four back-slashes at the start. That's because you really want two back-slashes, but you need an extra back-slash to "escape" each one.

Of course, such a path only works in the world of Windows. Have you considered using "file:" URLs instead, which might be more portable?


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
 
wood burning stoves
 
subject: Accessing File from other computer in network
 
Similar Threads
Some questions on the following code...
Returning array To Method
Question about getting arraylist's size
File Reading Error
simple io questions