android - SD Card new written file is zero bytes until reboot -
on samsung galaxy s5 latest lineage os nightly 9-aug-2017 (android 7.1.2):
i use fileoutputstream write file on app cache dir on sdcard , close it. sd card not adopted.
file file = new file(filename); fileoutputstream fout = new fileoutputstream(file, true); // yes, append if exists fout.write(buf, 0, len); // wrote few mbs here fout.close(); later, when list dir, file.length() 0 (zero) instead of few mb. can, however, read bytes in file. size still shows zero.
file dir = new file(dirname); file file = dir.listfiles()[index]; long filesize = file.length(); // filesize 0 until reboot other apps such total commander see 0 size, can copy non-zero file.
after phone reboot, file shows correct size.
the factory installed file browser, "files" shows correct size always.
also tried on emulators android version 6.0, 7.0, 7.1, 8.0 worked , size correct.
also doesn't happen on internal memory (or emulated storage). happens on sdcard.
did not see errors, exceptions while reading or writing etc.
Comments
Post a Comment