Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing to a new line in a file using Commons IO?

I know that

FileUtils.writeStringToFile(myfile.txt, "my string", true);

adds 'my string' to the end of myfile.txt, so it looks like

previous stringsmy string

But is there any way to use Commons IO to write a string to a new line in a file, to change the file to

previous strings
my string
like image 942
Chris Schmitz Avatar asked Oct 14 '13 13:10

Chris Schmitz


2 Answers

Java use \n to mark new line so try with:

FileUtils.writeStringToFile(myfile.txt, "\nmy string", true);
like image 176
user987339 Avatar answered Sep 17 '22 18:09

user987339


declare

final String newLine = System.getProperty("line.separator");

and in call, FileUtils.writeStringToFile(myfile.txt, yourVariable+newLine, true);

i use a variable , so this was more useful for me

like image 43
SanSolo Avatar answered Sep 18 '22 18:09

SanSolo