I have this code, which must remove files from the directory and the directory itself:
private static void removeTempFiles(File dir){
if(!dir.exists())
return;
if(dir.isDirectory()){
for(File f : dir.listFiles())
removeTempFiles(f);
dir.delete();
}
else {
dir.delete();
}
}
but executing this code don't remove all the files. From time to time it removes all files with the folder or removes only a few files
UPD: here is my creating file code:
File tempFolder = new File(tempPath);
tempFolder.mkdir();
tempFolder.mkdirs();
FileOutputStream fileOut = new FileOutputStream(tempPath+"/"+fileName);
OutputStreamWriter osw = new OutputStreamWriter(fileOut, "windows-1251");
try{
osw.write(file64);
} catch (IOException e){
e.printStackTrace();
}finally {
osw.close();
fileOut.close();
}