On Samsung Galaxy S5 with latest Lineage OS nightly 9-Aug-2017 (Android 7.1.2):
I use FileOutputStream to write to a file on the app cache dir on the SDCard and close it. SD Card is not adopted.
File file = new File(fileName);
FileOutputStream fout = new FileOutputStream(file, true); // yes, append if exists
fout.write(buf, 0, len); // wrote a few MBs here
fout.close();
Later, when I list the dir, File.length() is 0 (zero) instead of a few MB. I can, however, read all the bytes in the file. But size still shows as zero.
File dir = new File(dirName);
File file = dir.listFiles()[index];
long fileSize = file.length(); // fileSize is zero until I reboot
Other apps such as Total Commander also see zero size, but also can copy it to a non-zero file.
After phone reboot, file shows correct size.
The factory installed file browser, "Files" shows the correct size always.
Also I tried on emulators Android version 6.0, 7.0, 7.1, 8.0 but all worked and size was correct.
Also this doesn't happen on the internal memory (or emulated storage). Only happens on SDCard.
Did not see any errors, exceptions while reading or writing etc.