Skip to content

Instantly share code, notes, and snippets.

@dsaiztc
Created June 9, 2014 08:32
Show Gist options
  • Save dsaiztc/31cd90edf9ecd87c40f4 to your computer and use it in GitHub Desktop.
Save dsaiztc/31cd90edf9ecd87c40f4 to your computer and use it in GitHub Desktop.
Write to file in Java/Android
// Save to storage/folder/
File fileDir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/folder/");
fileDir.mkdirs();
String name = "file.txt";
File mFile = new File(fileDir, name);
BufferedWriter writer = null;
try
{
writer = new BufferedWriter(new FileWriter(mFile, true));
writer.write("something");
}
catch (IOException e)
{
}
finally
{
if (writer != null) writer.close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment