JDK-4031941 : java.io.FileWriter constructor throws incorrect exception
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 1.1
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_nt
  • CPU: x86
  • Submitted: 1997-02-12
  • Updated: 1998-01-07
  • Resolved: 1998-01-07
Related Reports
Duplicate :  
Description

Name: mc57594			Date: 02/12/97


If I construct a java.io.FileWriter for a file which is being
held open by the "more" program (Windows NT), it throws
java.io.FileNotFoundException.  In fact, the file is present.

The following program demonstrates this if it's run while the
argument file is held open in a "-- More --" prompt.

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.io.IOException;

public
class tt2 {
  static public void main(String argv[]) throws IOException {
    if (argv[1].equals("R")) {
      new BufferedReader(new FileReader(new File(argv[0])));
      System.out.println("opened db R");
    }
    else {
      new FileWriter(new File(argv[0]));
      System.out.println("opened db W");
    }
    System.in.read();
  }
}

D:\temp>java tt2 foo.bar W
java.io.FileNotFoundException: foo.bar
        at java.io.FileOutputStream.<init>(FileOutputStream.java:59)
        at java.io.FileOutputStream.<init>(FileOutputStream.java:93)
        at java.io.FileWriter.<init>(FileWriter.java:50)
        at tt2.main(tt2.java:17)


company  -  Object Design, Inc.  , email  -  ###@###.###
======================================================================

Comments
WORK AROUND Name: mc57594 Date: 02/12/97 ======================================================================
11-06-2004

EVALUATION Isn't this a "feature" of NT? -- mr@eng 2/12/1997 The FileReader constructors inherited from the FileInputStream constructors the design choice to throw only FileNotFoundExceptions rather than more general IOExceptions. Win32 does not allow a file to be opened for writing if it's already opened for reading, hence a FileNotFoundException must be thrown. It would be nice if there were various subclasses of FileNotFoundException to more precisely describe the error. Therefore I'm closing this as a duplicate of the RFE that's already been filed about that. -- mr@eng 1/7/1998
07-01-1998