<span style= "FONT-SIZE:18PX;" >1. Permissions add <uses-permission android:name= "Android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>< Uses-permission android:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/>public static String Getdatafolderpath (Context paramcontext) {return environment.getdatadirectory () + "/data/" + Paramco Ntext.getpackagename () + "/files"; public static String Getmyfiledir (context context) {return Context.getfilesdir (). toString (); public static String Getmycachedir (context context) {return Context.getcachedir (). toString (); }/** * @desc save content to file * @param filename * @param content * @throws Exception */public static V OID Save (context context, string fileName, string content, int module) {try {fileoutputstream os = con Text.openfileoutput (fileName, module); Os.write (Content.getbytes ()); Os.close (); } catch (Exception e) {e.Printstacktrace (); }}/** * @desc read file contents * @param fileName * @return */public static String read (Context Conte XT, String FileName) {try {FileInputStream FIS = context.openfileinput (fileName); Bytearrayoutputstream BOS = new Bytearrayoutputstream (); Byte[] B = new byte[1024]; int len = 0; while (len = Fis.read (b))! =-1) {bos.write (b, 0, Len); } byte[] data = Bos.tobytearray (); Fis.close (); Bos.close (); return new String (data); } catch (Exception e) {e.printstacktrace (); } return null; /** * @desc Save the text to the file in the SD card * @param context * @param fileName * @param content * @throws IOException */public static void Savetosdcard (context context, string fileName, String content) throws Ioexceptio n{File File = new file (environment. getExternalStorageDirectory (), fileName); FileOutputStream fos = new FileOutputStream (file); Fos.write (Content.getbytes ()); Fos.close (); }/** * @desc read SD card file contents * @param fileName * @return * @throws IOException */public static Strin G Readsdcard (String fileName) throws IOException {File File = new file (Environment.getexternalstoragedirec Tory (), fileName); FileInputStream fis = new FileInputStream (file); Bytearrayoutputstream BOS = new Bytearrayoutputstream (); byte[] buffer = new byte[1024]; int len = 0; while (len = fis.read (buffer))! =-1) {bos.write (buffer, 0, Len); } byte[] data = Bos.tobytearray (); Fis.close (); Bos.close (); return new String (data); }</span>
Android files saved to the app and SD card