Simple Write data/data/package name/files/sample.txt content into external storage
public void writeOnInternalStorageDir(Context mContext, String sFileName, String sBody) { File file = new File(mContext.getFilesDir(), "FolderName"); if (!file.exists()) { file.mkdir(); } try { File gpxfile = new File(file, sFileName); if (!gpxfile.exists()) { gpxfile.createNewFile(); } FileWriter writer = new FileWriter(gpxfile); writer.append(sBody); writer.flush(); writer.close(); } catch (Exception e) { e.printStackTrace(); } }
Example :
writeOnInternalStorageDir(MainActivity.this,"sample.txt","Welcome chandkony.blogspot.com");