I have a strange issue, when replacing a file by another. This code works well the first time :
String fileContent = "test";
File file = new File(Environment.getExternalStorageDirectory() + "/myApp/text.txt");
file.getParentFile().mkdirs();
if (file.exists())
file.delete();
try {
FileOutputStream fileOutputStream = new FileOutputStream(filePath);
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(fileOutputStream);
bufferedOutputStream.write(fileContent.getBytes());
bufferedOutputStream.close();
fileOutputStream.close();
} catch (Exception exception) {
exception.printStackTrace();
}
It creates a file with this content :
test
Then I execute the code again, replacing the "test" string by a longer string :
String fileContent = "admiral";
It removes the old file, create a new one, BUT it only write the 4 first characters :
admi
Finally, if I replace the content by a shorter string ("be", it creates a corrupted file :
be\00\00
But if I remove the file manually, it works... Very strange...
SOLVED : The problem was, gedit's cache! :s, by the way thx all for your help ! :)