In fact, just one way, you don't put all the code.
/** * Write file Method * @param content*/ Public Static voidWrite (String content) {Try { //determine if there is an actual SD card, and if the application has the ability to read and write the SD card, then return True if(Environment.getexternalstoragestate (). Equals (environment.media_mounted)) {//get the SD card directoryFile Sdcarddir =environment.getexternalstoragedirectory (); String Path="/app/"; File dir=NewFile (path); if(!dir.exists ()) {Dir.mkdirs (); } File targetfile=NewFile (Sdcarddir.getcanonicalpath () + path+"Aaa.txt"); //using Randomaccessfile is to append content to the original file base,//the use of OutputStream is to clear the contents before writingRandomaccessfile RAF =NewRandomaccessfile (TargetFile,"RW"); //the cursor moves to the end of the original file, and then writesRaf.seek (Targetfile.length ()); Raf.write (Content.getbytes ()); Raf.close (); } } Catch(Exception e) {e.printstacktrace (); } }
How to write TXT files to a specific path in Android