on Solaris, attempting to create a new FileOutputStream on a File which refers to a findable existing file, that happens to deny write priviledges, you get a FileNotFoundException. It should be some other IOException.
There's no way I know of programmatically to set this up, but you can place a file foo.txt in your working directory, and then execute
chmod a-w foo.txt
Then run a program containing:
void test() throws IOException {
try {
File f = new File("foo.txt");
FileInputStream fis = null;
FileOutputStream fos = null;
// verify that the file can be found
try {
fis = new FileInputStream(f);
} catch (FileNotFoundException fnex) {
System.out.prinln("first create readonly file foo.txt");
return;
}
fis.close();
try {
fos = new FileOuputStream(f);
System.out.println("foo.txt must be read only");
} catch (FileNotFoundException fnex) {
System.out.println(
"got FileNotFoundException for FileOutputStream, but not for FileInputStream");
}
}
There's no way I know of programmatically to set this up, but you can place a file foo.txt in your working directory, and then execute
chmod a-w foo.txt
Then run a program containing:
void test() throws IOException {
try {
File f = new File("foo.txt");
FileInputStream fis = null;
FileOutputStream fos = null;
// verify that the file can be found
try {
fis = new FileInputStream(f);
} catch (FileNotFoundException fnex) {
System.out.prinln("first create readonly file foo.txt");
return;
}
fis.close();
try {
fos = new FileOuputStream(f);
System.out.println("foo.txt must be read only");
} catch (FileNotFoundException fnex) {
System.out.println(
"got FileNotFoundException for FileOutputStream, but not for FileInputStream");
}
}
- duplicates
-
JDK-4107258 FileNotFoundException thrown when actually file isn't writeable
-
- Closed
-
- relates to
-
JDK-4065852 java.io: Different file-opening constructors throw different exceptions
-
- Closed
-