how to write to a file? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

how to write to a file?

6th Aug 2016, 11:41 AM
Yogesh Shriram Jangid
Yogesh Shriram Jangid - avatar
2 Answers
+ 1
Reading text files into memory and writing strings into a text file in Java 8 is finally a simple task. No messing around with readers and writers. The method Files.readAllLines reads all lines of a given file into a list of strings. You can simply modify this list and write the lines into another file via Files.write: List<String> lines = Files.readAllLines(Paths.get("res/mrk.js")); lines.add("print('foobar');"); Files.write(Paths.get("res/mrk-modified.js"), lines);
7th Aug 2016, 5:07 AM
Mohammad Reza Karimi
Mohammad Reza Karimi - avatar