1.保存到SD卡中:
获取SDCard的状态:
Environment.getExtemalStorageState()
Environment.MEDIA_MOUNTED手机装有SDCard,并且可以进行读写
获取SDCard的目录:Environment.getExtemalStorageDirectory()
//=============================================
File saveFile=new File("/sdcard/zhzhg.txt");
或:File sdCardDir=new File("/sdcard");//获取SD卡目录
File saveFile = new File(sdCardDir,"zhzhg.txt");
FileOutputStream outStream = new FileOutputStream(saveFile);
outStream.write("文件的读写".getBytes());
outStream.close();
2.保存到内存中:
getCacheDir()方法用于获取/data/data//cache目录
getFilesDir()方法用于获取/data/data//files目录
File file = new File(MyApplication.getInstance().getFilesDir()+"/"+path);
out = new PrintWriter(new BufferedWriter(new FileWriter(file, true)));
out.println(str);//在指定文件中加入内容
out.flush();