在近来做项目的过程中需要向SD写入文本文件用于记录app的相关信息,把过程记录下来;
1.添加权限
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
2.写接口
public void writeFileSdcard(String fileName, String message) {
try {
FileOutputStream fout = new FileOutputStream(fileName);
fout.write(message.getBytes());
fout.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
使用示例
logwrite.writeFileSdcard(Environment.getExternalStorageDirectory().getPath()+"/001.txt",
"hello world!");