简体   繁体   中英

FileNotFoundException while creating a file with java in Ubuntu?

I have been trying to convert millions of xml documents to txt files. After reading each xml I parse the required content and write it into a new text file in a new drectory.

But when I process some large number of files like more than 7000, I am getting the FileNotFoundException.

Here is the stackTrace:

java.io.FileNotFoundException: /media/volume/data/File8838.txt (Input/output error)
    at java.io.FileOutputStream.open(Native Method)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:212)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:165)
    at java.io.FileWriter.<init>(FileWriter.java:90)
    at com.infoarmy.ir.ml.FormatData.main(FormatData.java:126)

The code snippet of FormatData is:

File newFile = new File("/media/volume/data/File8838.txt");
newFile.getParentFile().mkdirs();
BufferedWriter writer = new BufferedWriter(new FileWriter(newFile));
writer.write(builder.toString());
writer.close();

Here is the strange thing: After this exception happens I am unable to create the file using vi also. Error 212

Can anyone point out why this happens?

try

writer.flush()

before closing it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM