java - Adding new lines of text in a text file -
my app records sounds. once sound recorded, user asked input new file name. i'm trying next add file names in text file can read later array make listview.
this code:
//this in oncreate file recordedfiles = new file(externalstoragepath + file.separator + "/android/data/com.whizzappseasyvoicenotepad/recorded files.txt"); if(!recordedfiles.exists()) { try { recordedfiles.createnewfile(); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } } //this executes everytime text entered , button clicked try { string content = input.gettext().tostring(); filewriter fw = new filewriter(recordedfiles.getabsolutefile()); bufferedwriter bw = new bufferedwriter(fw); bw.write(">" + content + ".mp3"); bw.close(); } catch (ioexception e) { e.printstacktrace(); } now problem everytime record new file, previous line overwritten. if record 2 files 'text1' , 'text2', after i've recorded text1, txt file show text1, after recorded text2, text2 overwrite text1 instead of inserting new line.
i tried adding:
bw.newline() before
bw.write(">" + content + ".mp3"); but doesn't work.
if record 3 sounds , name them sound1, sound2 , sound3, want result:
>sound1 >sound2 >sound3
use filewriter constructor boolean append argument
filewriter fw = new filewriter(recordedfiles.getabsolutefile(), true); // ^^^^ this let file append text @ end instead overwriting previous content.
Comments
Post a Comment