I need help to make a very simple app for android that just creates text files on the click of a button. Can anyone help me with the coding? I already made the activity_main.xml set out already, but now I want to know how I can get a button to create a .txt or a .doc file which users can write in! (Something like a notepad)
Asked
Active
Viewed 4,251 times
-5
-
google it once .. m sure u will find answer if any more query u can add comments – KOTIOS Nov 06 '13 at 06:50
-
http://edisontus.blogspot.sg/2013/01/simple-notepad-for-android.html – Amulya Khare Nov 06 '13 at 07:01
-
http://stackoverflow.com/questions/8152125/how-to-create-text-file-and-insert-data-to-that-file-on-android – Kalai.G Nov 06 '13 at 07:05
1 Answers
2
Try this
public void addTextToFile(String text) {
File logFile = new File("sdcard/" + "MyFile.txt");
if (!logFile.exists()) {
try {
logFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
try {
BufferedWriter buf = new BufferedWriter(new FileWriter(logFile, true));
buf.append(text);
buf.newLine();
buf.close();
} catch (IOException e) {
e.printStackTrace();
}
}

Biraj Zalavadia
- 28,348
- 10
- 61
- 77