-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
1.4.0
-
sparc
-
solaris_2.6
Name: dsR10051 Date: 10/10/2000
The method
java.io.File.createNewFile() works incorrectly if the pathname of the File
is a system-dependent default directory. In this case mathod throws IOException,
while it returns false (does not throw IOException) for any other
existent directory. It seems that the last behavior is more correct for
root directory.
Here is a minimized test:
------
import java.io.*;
public class FileTest01 {
public static void main(String argv[]) {
boolean res;
File testFile1 = new File("", "");
File testFile2 = new File("", "usr");
System.out.println("File: " + testFile1);
System.out.println(" exists: " + testFile1.exists());
System.out.println(" isDirectory: " + testFile1.isDirectory());
try {
System.out.println("Trying to create ...");
res = testFile1.createNewFile();
System.out.println("Created: " + res);
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("File: " + testFile2);
System.out.println(" exists: " + testFile2.exists());
System.out.println(" isDirectory: " + testFile2.isDirectory());
try {
System.out.println("Trying to create ... ");
res = testFile2.createNewFile();
System.out.println("Created: " + res);
} catch (IOException e) {
e.printStackTrace();
}
}
}
--- Output ---
%uname -a
SunOS sword 5.6 Generic_105181-19 sun4u sparc SUNW,Ultra-2
%java -version
java version "1.4.0beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0beta-b35)
Java HotSpot(TM) Client VM (build 1.4beta-B35, mixed mode)
%java FileTest01
File: /
exists: true
isDirectory: true
Trying to create ...
java.io.IOException: Invalid argument
at java.io.UnixFileSystem.createFileExclusively(Native Method)
at java.io.File.createNewFile(File.java:683)
at FileTest01.main(FileTest01.java:16)
File: /usr
exists: true
isDirectory: true
Trying to create ...
Created: false
%
======================================================================