一,添加函數
try {
File saveFile=new File("/sdcard/zhzhg.txt");
FileOutputStream outStream = new FileOutputStream(saveFile);
try {
outStream.write("文件的讀寫".getBytes());
}
catch (IOException ex)
{
Logger.getLogger(DeviceListActivity.class.getName()).log(Level.SEVERE, null, ex);
}
try
{
outStream.close();
}
catch (IOException ex)
{
Logger.getLogger(DeviceListActivity.class.getName()).log(Level.SEVERE, null, ex);
}
} www.2cto.com
catch (FileNotFoundException ex)
{
Logger.getLogger(DeviceListActivity.class.getName()).log(Level.SEVERE, null, ex);
}
二,設置向存儲卡讀寫權限
在AndroidMainfest.xml文件中添加:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"></uses-permission>