Name: dbT83986 Date: 03/09/99
When creating FileOutputStream for a file whose name starts with 'com' it does not create a file or outputs data until eventually
it generates an FileNotFoundException.
Exactly the same problem exists for a FileWriter.
Here is an example source code:
----------------------------
import java.io.*;
public class TestWrite {
public static void main (String args[]) throws Exception
{
String testString = "This is just a test\n";
FileOutputStream out = null;
for (int i = 0; i < 10 ; i++ )
{
String fileName = "com" + (i + 1) + ".txt";
File fl = new File(fileName);
if (fl.exists())
{
System.out.println("Deleting file " + fl.getName());
fl.delete();
fl = new File(fileName);
}
System.out.println("Creating file " + fl.getName());
out = new FileOutputStream(fl);
System.out.println("Creating out as " + fl.getAbsolutePath());
for (int j = 0; j < 10; j++ )
{
out.write(testString.getBytes());
}
}
}
}
---------------------
Compile
javac TestWrite.java
Run java TestWrite
Program output:
Deleting file com1.txt
Creating file com1.txt
Creating out as D:\test\com1.txt
Deleting file com2.txt
Creating file com2.txt
Creating out as D:\test\com2.txt
Deleting file com3.txt
Creating file com3.txt
java.io.FileNotFoundException: com3.txt
at java.io.FileOutputStream.<init>(FileOutputStream.java:61)
at java.io.FileOutputStream.<init>(FileOutputStream.java:106)
at TestWrite.main(Compiled Code)
-------
Even though files com1.txt and com2.txt are reported as created they are not!!
(Review ID: 55043)
======================================================================
- duplicates
-
JDK-8278848 A problem occurs when entering a specific file name in FileOutputStream
- Closed