Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6359397

FileInputStream.read() and FileOutputStream.write() throw IOException: No such file or directory

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 6
    • Fix Version/s: 7
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b12
    • CPU:
      generic
    • OS:
      generic
    • Verification:
      Not verified

      Description

      It would be meaningful if the error message says 'Stream closed' insteadof 'No such file or directory'(windows)/'Bad file number(solaris) whenever try to read with FileInputStream.read() after closing standard input/output/error stream.
        Also Checking ahead whether a stream is closed, stops overhead of calling native mathod.
      Please see the follwoing code, version,Result windows/solaris

      import java.io.*;
      class TestErrMsg {

      public static void main(String... args) {

      FileInputStream fis = new FileInputStream(FileDescriptor.in);
      System.out.println("These Error Messages :");
      System.out.println("--------------------");
      try {
      System.in.close();
      fis.read();
      }catch(IOException e){
      System.out.print("(1) ");
      e.printStackTrace();
      }
      FileOutputStream fos = new FileOutputStream(FileDescriptor.out);
      try {
      System.out.close();
      fos.write(1);
      }catch(IOException e){
      System.err.print("(2) ");
      e.printStackTrace();
      }

      System.err.println("\nCan be changed like This message :");
      System.err.println("--------------------------------");
      try{
      System.in.read();
      }catch(IOException e){
      e.printStackTrace();
      }
      }

      }

      <version>
      C:\work\TestDev\Bug>java -version
      java version "1.6.0-tbell_2005_11_29.17.38.41"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0-tbell_2005_11_29.17.38.41-b333)
      Java HotSpot(TM) Client VM (build 1.6.0-rc-b61, mixed mode)
      </version>

      <Result-windows>
      C:\work\TestDev\Bug>java TestErrMsg
      These Error Messages :
      --------------------
      (1) java.io.IOException: No such file or directory
              at java.io.FileInputStream.read(Native Method)
              at TestErrMsg.main(TestErrMsg.java:14)
      (2) java.io.IOException: No such file or directory
              at java.io.FileOutputStream.write(Native Method)
              at TestErrMsg.main(TestErrMsg.java:22)

      Can be changed like This message :
      --------------------------------
      java.io.IOException: Stream closed
              at java.io.BufferedInputStream.getBufIfOpen(BufferedInputStream.java:145)
              at java.io.BufferedInputStream.fill(BufferedInputStream.java:189)
              at java.io.BufferedInputStream.read(BufferedInputStream.java:235)
              at TestErrMsg.main(TestErrMsg.java:31)

      </Result-windows>
      <Result-solaris>
      These Error Messages :
      --------------------
      (1) java.io.IOException: Bad file number
              at java.io.FileInputStream.read(Native Method)
              at TestErrMsg.main(TestErrMsg.java:14)
      (2) java.io.IOException: Bad file number
              at java.io.FileOutputStream.write(Native Method)
              at TestErrMsg.main(TestErrMsg.java:22)

      Can be changed like This message :
      --------------------------------
      java.io.IOException: Stream closed
              at java.io.BufferedInputStream.getBufIfOpen(BufferedInputStream.java:145)
              at java.io.BufferedInputStream.fill(BufferedInputStream.java:189)
              at java.io.BufferedInputStream.read(BufferedInputStream.java:235)
              at TestErrMsg.main(TestErrMsg.java:31)
      </Result-solaris>

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              jhangalsunw Jayalaxmi Hangal (Inactive)
              Reporter:
              rgutupalsunw Rajendra Gutupalli (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: