This article is very helpful for you .This function is used to write json data in file
set permission in manifestuses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
public static void WriteSettings(Context context, String data, String file) throws IOException { FileOutputStream fos= null; OutputStreamWriter osw = null; fos= context.openFileOutput(file,Context.MODE_PRIVATE); osw = new OutputStreamWriter(fos); osw.write(data); osw.close(); fos.close(); }
This function is used to read file data.
public static String ReadSettings(Context context, String file) throws IOException { FileInputStream fis = null; InputStreamReader isr = null; String data = null; fis = context.openFileInput(file); isr = new InputStreamReader(fis); char[] inputBuffer = new char[fis.available()]; isr.read(inputBuffer); data = new String(inputBuffer); isr.close(); fis.close(); return data; }
No comments:
Post a Comment