SDCard
往SDCard存文件,必须判断手机是否安装有SDCard,并且可以进行读写,访问SDCard必须在AndroidMainfest.xml中加入访问权限
<!--在SDCard中创建与删除文件权限-->
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
<!--往SDCard写数据权限-->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
View Code
if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
//可以读写
File sdCardDir = Environment.getExternalStorageDirectory(); //获取SDCard目录
//或者File sdCardDir = new File("mnt/sdcard");
File saveFile = new File(sdCardDir, "test.txt");
try {
FileOutputStream outStream = new FileOutputStream(saveFile);
outStream.write("test sdcard".getBytes());
outStream.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}