系统是我自己编译的,有修改写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);
}
现在的问题就是,我写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);
}
解决方案 »
- 菜鸟问一个关于zxing的问题
- Camera如何关闭声音; 这个问题解决了好久了。
- win7下Eclipse安装ADT失败?
- 【求助】SQLiteOpenHelper构造函数的Context
- 模拟器问题:部署时不报错,模拟器可正常运行,但是程序没被有正确部署
- 把android中的linpng移植到windows mobile上
- adk命令无法使用,请问怎么回事
- 愁人的ANR(求助)
- 写一个工具类,获得手机屏幕的大小
- webview链接网站弹框问题
- 如何定制MaterialDialog的确认和取消按钮,我想使用一个大按钮?
- 在Android studio中使用了fragment显示listview但是运行的时候一点击listview中的行就闪退无法进入下一页
加上fos.getFD().sync();即可