Skip to content

Instantly share code, notes, and snippets.

@Gkemon
Last active February 27, 2020 06:27
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 Gkemon/e2e50483ce2618b487d3da8b90941d20 to your computer and use it in GitHub Desktop.
Save Gkemon/e2e50483ce2618b487d3da8b90941d20 to your computer and use it in GitHub Desktop.
String msg="My name is emon";
String directory_path = Environment.getExternalStorageDirectory().getPath();
File file = new File(directory_path,"/Android"); //"/Android" is the folder name
if(!file.exists()){
file.mkdir();
}
if (!file.exists()) {
file.createNewFile();
}
if (file.exists()) {
try{
FileWriter writer = new FileWriter(new File( file,"file.txt"));
writer.append(msg);
writer.flush();
writer.close();
Toast.makeText(this,"File is created",Toast.LENGTH_LONG).show();
}catch (Exception e){
e.printStackTrace();
Toast.makeText(this,"File is not created "+e.getMessage(),Toast.LENGTH_LONG).show();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment