I have this code:
File dir = new File("/home/user/somedir");
for (File child : dir.listFiles()) {
System.out.println(child.getName());
if(!child.isDirectory()){
readLines(child.getPath()); //do something with this file
}
}
And i get this output:
cestino
arabika
wkurwi�%87_si�%99
java.io.FileNotFoundException: /home/user/somedir/wkurwi�%87_si�%99 (No such file or directory)
child.renameTo()
also doesn't work.
new FileReader(child)
instead of child.getPath()
doesn't work too:
java.io.FileNotFoundException: /home/user/somedir/wkurwi�%87_si�%99 (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at java.io.FileReader.<init>(FileReader.java:72)
I know if I manually change file name then file can be easliy read. But why this file is listed by listFiles method but i can't read file using this name? Is there any solution? I have a lot of this files with wrong encoding so I cant change all names manually :) But if there is some automatic method to change their names, even file1, file2 is good.