Created
December 17, 2015 20:16
-
-
Save rsicarelli/cc5df64907cad77f7a49 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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