Simple Java Code for Write txt file in Andriod :
try {
File newFolder = new File(Environment.getExternalStorageDirectory(), "TestFolder");
if (!newFolder.exists()) {
newFolder.mkdir();
}
try {
//String name="Welcome";
File file = new File(newFolder, "MyTest" + ".txt");
file.createNewFile();
PrintWriter fos = new PrintWriter(file);
for (int i = 0; i < finallist1.size(); i++) {
fos.write(String.valueOf(finallist1.get(i))+"\t");
fos.write("ln");
fos.write(String.valueOf(finallist.get(i))+"\t");
}
Toast.makeText(getApplicationContext(), "Saved", Toast.LENGTH_LONG).show();
fos.flush();
fos.close();
} catch (Exception ex) {
System.out.println("ex: " + ex);
}
} catch (Exception e) {
System.out.println("e: " + e);
}
No comments:
Post a Comment