1、保存到/data/user/0/com.flx.testfilestorage/files
try {
//mode参数注意下,这里使用的Context.MODE_PRIVATE
FileOutputStream fileOutputStream = new FileOutputStream(new File(externalFile, "aaaa.txt"),true);//在文件后添加
String content="ssdfsdfd";
fileOutputStream.write(content.getBytes());
outputStream.write( "Use OutputStream Create file\n".getBytes() );
outputStream.close();
} catch (IOException e) {
Log.d( TAG, "outputStream err:"+e.getMessage() );
}
2、保存到/storage/emulated/0/Android/data/com.flx.testfilestorage/files
String state = Environment.getExternalStorageState();
File externalFile = context.getExternalFilesDir( null );
File[] externalFiles = context.getExternalFilesDirs( Environment.DIRECTORY_PICTURES );
for (File file : externalFiles) {
Log.d( TAG, "state="+ state + ";\nexternalFiles=" + file + ";\nexternalFile="+externalFile);
try {
FileOutputStream fileOutputStream = new FileOutputStream( new File( file, "aaaa.txt" ) );
fileOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
|