Name: rm29839 Date: 05/21/98
It is very difficult to determine if a file is available for use.
FileNotFoundException (with the same message)is generated in two cases:
1. The file does not exist.
2. The file exists but is locked by another user.
The absence of the alternate message text means programmers have to elimate
all the probable causes and then assume the improbable:
File file = new File(fileName);
if (file.exists()) { // whew it exists
if (file.canWrite()) { // whew I'm allowed
try {
DataOutputStream = new ...... new FileOutputStream(file);
catch (FileNotFoundException e) { // I guess not - perhaps someone is using it.
...
Every programmer has to go through these contortions to generate an accurate message
to the program user.
Also note that java.io.File could use an isAvailableRead/Write() function (or similar).
(Review ID: 29111)
======================================================================
- relates to
-
JDK-4167937 Add GetLastErrorString entry points to JVM and HPI
-
- Closed
-
-
JDK-4079140 IOException should have subclasses to better describe failure
-
- Closed
-