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

java.io.FileOutputStream ctors throw FileNotFoundException for read-only files

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: P3 P3
    • None
    • 1.1.5, 1.2.0
    • core-libs
    • generic, sparc
    • solaris_2.5.1, solaris_2.6

      on Solaris, attempting to create a new FileOutputStream on a File which refers to a findable existing file, that happens to deny write priviledges, you get a FileNotFoundException. It should be some other IOException.

      There's no way I know of programmatically to set this up, but you can place a file foo.txt in your working directory, and then execute
      chmod a-w foo.txt

      Then run a program containing:
      void test() throws IOException {
      try {
      File f = new File("foo.txt");
      FileInputStream fis = null;
      FileOutputStream fos = null;

      // verify that the file can be found
      try {
      fis = new FileInputStream(f);
      } catch (FileNotFoundException fnex) {
      System.out.prinln("first create readonly file foo.txt");
      return;
      }
      fis.close();

      try {
      fos = new FileOuputStream(f);
      System.out.println("foo.txt must be read only");
      } catch (FileNotFoundException fnex) {
      System.out.println(
      "got FileNotFoundException for FileOutputStream, but not for FileInputStream");
      }

      }

            mr Mark Reinhold
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: