Background
Some things can exist in their own definition of the file inside, this file can be in the phone, can be in the SD card, here is the main introduction of the SD card storage and reading it ~
Code
Public classSave { Public Static voidSavefile2card (Context context,string username,string password) {File file=NULL; FileOutputStream Fos=NULL; Try { if(Environment.MEDIA_MOUNTED.equals (Environment.getexternalstoragestate ())) {//file = new file ("/sdcard/info.txt");File =NewFile (Environment.getexternalstoragedirectory (), "Info.txt"); FOS=Newfileoutputstream (file); Fos.write ((username+"!!!!" +password). getBytes ()); } Else{toast.maketext (context,"SD Wood has", Toast.length_long). Show (); } } Catch(Exception e) {//TODO Auto-generated catch blockE.printstacktrace (); Toast.maketext (Context,"Wrong", Toast.length_long). Show (); Try{fos.close (); } Catch(IOException E1) {//TODO Auto-generated catch blockE1.printstacktrace (); } }
}}
The above is the stored code, where the environment.media_mountedis used to see if the mount.
Public classRead { Public StaticMap<string,string>Getsavefile (Context context) {//File File =new file (Context.getfilesdir (), "Info.txt");File File =NewFile (Environment.getexternalstoragedirectory (), "Info.txt"); Try{FileInputStream fis=Newfileinputstream (file); BufferedReader BR=NewBufferedReader (NewInputStreamReader (FIS)); String Str=Br.readline (); String[] Infos= Str.split ("!!!!"); Map<String,String> map =NewHashmap<string, string>(); Map.put ("Username", infos[0]); Map.put ("Password", infos[1]); Br.close (); returnmap; } Catch(Exception e) {//TODO Auto-generated catch blockE.printstacktrace (); return NULL; } finally { } }}
The above is read code, will be saved will read, stored in so read out scatter ~
I'm the dividing line of the king of the Land Tiger.
Source code: HTTP://PAN.BAIDU.COM/S/1DD1QX01
Sdcard.zip
Reprint Please specify source: http://www.cnblogs.com/yydcdut/p/3720648.html