-5

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

1 Answer 1

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(); } } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.