This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
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 OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP 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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Accessing File from other computer in network