加入读写权限
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
写的方法
/运行的时候把方法调用一下 public boolean writeListIntoSDcard(){ if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){ File sdCardDir = Environment.getExternalStorageDirectory();//获取sd卡目录 //写入的文件名 File sdFile = new File(sdCardDir, "user.text"); try { FileOutputStream fos = new FileOutputStream(sdFile); ObjectOutputStream oos = new ObjectOutputStream(fos); //要写入的集合 (如果要写入的是对象直接把对象名字替换掉集合名字就行了) oos.writeObject(list2);//写入 fos.close(); oos.close(); return true; } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); return false; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); return false; } } else { return false; } }