一个关于写U盘后没数据的问题

xiezonglin xiezonglin 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
系统是我自己编译的,有修改写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);
}
...全文

相关推荐

评论 3
收藏 已收藏
分享
返回顶部
xiezonglin
Android 80,489 成员 91,371 内容