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)
3
- google it once .. m sure u will find answer if any more query u can add commentsKOTIOS– KOTIOS2013-11-06 06:50:52 +00:00Commented Nov 6, 2013 at 6:50
- edisontus.blogspot.sg/2013/01/simple-notepad-for-android.htmlAmulya Khare– Amulya Khare2013-11-06 07:01:33 +00:00Commented Nov 6, 2013 at 7:01
- stackoverflow.com/questions/8152125/…Kalai.G– Kalai.G2013-11-06 07:05:13 +00:00Commented Nov 6, 2013 at 7:05
Add a comment |
1 Answer
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(); } }