• 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

Accessing File from other computer in network

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
 
Ranch Hand
Posts: 1970
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
reply
    Bookmark Topic Watch Topic
  • New Topic