file I/O question

From: slurper (slurper1234_at_skynet.be)
Date: 03/22/05

  • Next message: Adam: "B+-Tree"
    Date: Tue, 22 Mar 2005 20:36:06 +0100
    
    

    try {

    FileInputStream fis = new FileInputStream("README.TXT");
    int n;
    while ((n = fis.available()) > 0) {
            byte[] b = new byte[n];
            int result = fis.read(b);
            if (result == -1) break;
            String s = new String(b);
            System.out.print(s); }
            // End while
            }
    // End try catch (IOException e) {System.err.println(e);}
    System.out.println();

    i wonder if this code snippet is correct. I think it is possible that not
    all content of README.TXT will be printed.
    the loop will run as long as there are bytes available without blocking the
    program. but will there be bytes available after opening the file? the
    program needs to block immediately waiting for I/O, or do i see this wrong?

    tx


  • Next message: Adam: "B+-Tree"

    Relevant Pages

    • OuputStream question
      ... I an article in JDJ i found the following code snippet: ... public void write (int c) throws IOException { ...
      (comp.lang.java.help)
    • GETPID after popen command
      ... I have some shell scripts and I want to execute them via a C program. ... This C program needs: ... int main ...
      (comp.unix.programmer)