80,337
社区成员
发帖
与我相关
我的任务
分享
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);
}