系統是我自己編譯的,有修改寫u盤權限
現在的問題就是,我寫u盤檔案后,直接拔出來,到電腦上,檔案有在,但是沒資料
如果我在存盤那邊卸載u盤,或者把安卓關機再拔出u盤,那么就有資料
但是很難要求客戶這么做,有沒有辦法把資料寫入u盤而不是快取?
我的代碼如下
public static void writeSDFile_UTF8(Context ctx,String fileName, String write_str) throws IOException{
File file = new File(fileName);
if (!file.exists()) file.createNewFile();//建立檔案
FileOutputStream fos = new FileOutputStream(file);
if (file.length() < 1) {
final byte[] bom = new byte[] { (byte)0xEF, (byte)0xBB, (byte)0xBF };
fos.write(bom);
}
OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF-8");
osw.write(write_str);
osw.flush();
osw.close();
fos.flush();
fos.close();
MediaScannerConnection.scanFile(ctx, new String[] { file.getAbsolutePath() }, null, null);
}
uj5u.com熱心網友回復:
修改安卓原始碼來解決的方案也可以接受uj5u.com熱心網友回復:
已解決加上fos.getFD().sync();即可
uj5u.com熱心網友回復:
您好,請問這個現象具體原因是什么呢?轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/126704.html
標籤:Android
上一篇:app移植到手機出現閃退問題
下一篇:IOS插件腳本
