Skip to content

Instantly share code, notes, and snippets.

@rsicarelli
Created December 17, 2015 20:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rsicarelli/cc5df64907cad77f7a49 to your computer and use it in GitHub Desktop.
Save rsicarelli/cc5df64907cad77f7a49 to your computer and use it in GitHub Desktop.
private void writeToFile(final String data) {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
try {
Context context = Application.getApplication().getBaseContext();
File path = context.getExternalFilesDir(null);
File file = new File(path, "my_json.json");
FileOutputStream stream = new FileOutputStream(file);
stream.write(data.getBytes());
stream.close();
MyLog.info("done with the json");
} catch (IOException e) {
Log.e("Exception", "File write failed: " + e.toString());
}
return null;
}
}.execute();
}
@Override
public void someMethod() {
InputStream is = Application.getApplication().getResources().openRawResource(R.raw.my_json);
final BufferedReader reader = new BufferedReader(new InputStreamReader(is));
MockResponse mockResponse = new Gson().fromJson(reader, MockResponse.class);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment