1.调用Environment.getExternalStorageState()判断手机上是否插入了SD卡,并且应用程序具有读写SD卡的权限。
Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)
返回值为true代表该应用程序具有读写SD卡的权限。
2.调用Environment的getExternalStorageDirectory()方法来获取外部存储器,也就是SD卡的目录。
Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)
返回值为true代表该应用程序具有读写SD卡的权限。
2.调用Environment的getExternalStorageDirectory()方法来获取外部存储器,也就是SD卡的目录。
3.使用FileInputStream FileOutputStream FileReader FIleWriter 读写SD卡里的文件。
class Utils {
public void MyWrite(String data) throws Exception {
File sDfile = Environment.getExternalStorageDirectory();
File f = new File(sDfile, "demo.txt");
FileOutputStream fos = new FileOutputStream(f);
fos.write(data.getBytes());
fos.flush();
fos.close();
}
public String MyRead() throws Exception {
File sdFile = Environment.getExternalStorageDirectory();
File f = new File(sdFile, "demo.txt");
FileInputStream fis =