This is a very minor bug. If a file isn't writeable and a program
attempts to write to it, the exception thrown is java.io.FileNotFoundException.
This is a bit confusing, since the file does exist. Suppose the file
/home/mrm/notwriteable exists but has write permissions turned off.
The following program demonstrates the bug. Thanks to Charlie Lai for
figuring this out.
import java.io.*;
public class WriteFile {
public static void main(String args[]) {
try {
PrintWriter out = new PrintWriter
(new BufferedWriter
(new FileWriter("/home/mrm/notwriteable")));
out.println("hi there");
out.flush();
} catch (Exception e) {
System.out.println(e.toString());
}
}
}
attempts to write to it, the exception thrown is java.io.FileNotFoundException.
This is a bit confusing, since the file does exist. Suppose the file
/home/mrm/notwriteable exists but has write permissions turned off.
The following program demonstrates the bug. Thanks to Charlie Lai for
figuring this out.
import java.io.*;
public class WriteFile {
public static void main(String args[]) {
try {
PrintWriter out = new PrintWriter
(new BufferedWriter
(new FileWriter("/home/mrm/notwriteable")));
out.println("hi there");
out.flush();
} catch (Exception e) {
System.out.println(e.toString());
}
}
}
- duplicates
-
JDK-4106518 java.io.FileOutputStream ctors throw FileNotFoundException for read-only files
-
- Closed
-