Cannot read from file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ioshonowo
    New Member
    • Sep 2007
    • 31

    Cannot read from file

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

    [CODE=java]
    static int NumberofLines(S tring file) throws IOException{
    RandomAccessFil e reader = null;
    int lineCount = 0;
    try {
    reader = new RandomAccessFil e(file + "/perso.txt", "r");
    for (String line = reader.readLine (); line != null;
    line = reader.readLine ()) {
    lineCount++;
    }
    } catch (IOException e) {
    System.err.form at("Could not read %s: %s%n", file, e);
    System.exit(1);
    } finally {
    if (reader != null) {
    try {
    reader.close();
    } catch (IOException e) {}
    }
    }
    System.out.prin tln("Number of Lines are " + lineCount);
    return lineCount;
    }
    [/CODE]

    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\oshono wo\My Documents\Chams to be burnt
    FIDELITY_ChamsF iles_2007112810 04: java.io.FileNot FoundException: \\10.10.0.127\c $\Documents and Settings\oshono wo\My Documents\Chams to be burnt
    FIDELITY_ChamsF iles_2007112810 04\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
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    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

    Comment

    • ioshonowo
      New Member
      • Sep 2007
      • 31

      #3
      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?

      Comment

      Working...