Skip to content

Instantly share code, notes, and snippets.

@alfredoem
Created April 21, 2020 22:00
Show Gist options
  • Save alfredoem/3a985566bd0bd37d3aee3ab2e3786d96 to your computer and use it in GitHub Desktop.
Save alfredoem/3a985566bd0bd37d3aee3ab2e3786d96 to your computer and use it in GitHub Desktop.
try {
File nuevaCarpeta = new File(Environment.getExternalStorageDirectory(), "NombreNuevaCarpeta");
if (!nuevaCarpeta.exists()) {
nuevaCarpeta.mkdir();
}
try {
File file = new File(nuevaCarpeta, "ArchivoDePrueba" + ".txt");
file.createNewFile();
FileOutputStream stream = new FileOutputStream(file);
try {
stream.write(new Gson().toJson("objeto o string sin Gson")).getBytes());
} finally {
stream.close();
}
} catch (Exception ex) {
Log.e("Error", "ex: " + ex);
}
} catch (Exception e) {
Log.e("Error", "e: " + e);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment