1. Save to SD card:
Get the status of SDcard:
Environment.getextemalstoragestate ()
Environment.media_mounted mobile phone is equipped with sdcard and can read and write
Get the directory of SDcard: Environment.getextemalstoragedirectory ()
//=============================================
File Savefile=new file ("/sdcard/zhzhg.txt");
Or: File Sdcarddir=new file ("/sdcard");//get SD card Directory
File SaveFile = new file (Sdcarddir, "zhzhg.txt");
FileOutputStream OutStream = new FileOutputStream (saveFile);
Outstream.write ("Read and Write Files". GetBytes ());
Outstream.close ();
2. Save to Memory:
The Getcachedir () method is used to get the/data/data//cache directory
The Getfilesdir () method is used to get the/data/data//files directory
File File = new file (Myapplication.getinstance (). Getfilesdir () + "/" +path);
out = new PrintWriter (new BufferedWriter (New FileWriter (file, true));
Out.println (str);//Add content to the specified file
Out.flush ();
Android file saved to SD card and memory