File.length should return 0 for non-existent files

This commit is contained in:
Joel Dice 2011-01-17 09:48:34 -07:00
parent c855224d14
commit 4a9ff55060
2 changed files with 7 additions and 1 deletions

View File

@ -331,7 +331,7 @@ Java_java_io_File_length(JNIEnv* e, jclass, jstring path)
}
}
return -1;
return 0;
}
extern "C" JNIEXPORT void JNICALL

View File

@ -4,6 +4,10 @@ import java.io.File;
import java.io.IOException;
public class FileOutput {
private static void expect(boolean v) {
if (! v) throw new RuntimeException();
}
private static void test(boolean appendFirst) throws IOException {
try {
FileOutputStream f = new FileOutputStream("test.txt", appendFirst);
@ -33,6 +37,8 @@ public class FileOutput {
}
public static void main(String[] args) throws IOException {
expect(new File("nonexistent-file").length() == 0);
test(false);
test(true);
}