By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,921 Members | 1,479 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,921 IT Pros & Developers. It's quick & easy.

Cannot read from file

P: 31
Hello. I am trying to read the number of lines in a file using this function

Expand|Select|Wrap|Line Numbers
  1. static int NumberofLines(String file) throws IOException{
  2.         RandomAccessFile reader = null;
  3.         int lineCount = 0;    
  4.         try {
  5.             reader = new RandomAccessFile(file + "/perso.txt", "r");
  6.             for (String line = reader.readLine(); line != null;
  7.                     line = reader.readLine()) {
  8.                 lineCount++;
  9.             }
  10.         } catch (IOException e) {
  11.             System.err.format("Could not read %s: %s%n", file, e);
  12.             System.exit(1);
  13.         } finally {
  14.             if (reader != null) {
  15.                 try {
  16.                     reader.close();
  17.                 } catch (IOException e) {}
  18.             }
  19.         }
  20.         System.out.println("Number of Lines are " + lineCount);
  21.         return lineCount;
  22.     }
  23.  
However I get the following error when I try and run my program I get the following error: -
Could not read \\10.10.0.127\c$\Documents and Settings\oshonowo\My Documents\Chams to be burnt
FIDELITY_ChamsFiles_200711281004: java.io.FileNotFoundException: \\10.10.0.127\c$\Documents and Settings\oshonowo\My Documents\Chams to be burnt
FIDELITY_ChamsFiles_200711281004\perso.txt (The filename, directory name, or volume label syntax is incorrect)
Java Result: 1

I have shared the folder oshonowo on the 10.10.0.127 machine.

Pls help
Dec 4 '07 #1
Share this Question
Share on Google+
2 Replies


Expert 10K+
P: 11,448
Read the error text: a file name cannot contain IP addresses or host names.
Use a URL instead given that name, connect it and get an InputStream from that
connection. Start at the API documentation for the URL class.

kind regards,

Jos
Dec 4 '07 #2

P: 31
The file could contain an ip address using the previous run time environment. This program ran using an ip address and was working before. Is it the change in run time environment that caused this?
Dec 5 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.