Answer the question
In order to leave comments, you need to log in
How to edit text files in java line by line?
The essence of the question is how to edit a text file located in resources line by line (for example, delete a certain line or update it, write it or read it). Thanks in advance for your answer
Answer the question
In order to leave comments, you need to log in
List lines = Files.readAllLines(Paths.get("res/file.txt"));
//перебираете циклом
for(String s : lines)
{
s = "Бла-бла-бла!"
}
/* Если нужно удалить - для перебора используйте Iterator.
Не забудьте : */
Files.write(Paths.get("res/file.txt"), lines);
//иначе результат не запишется
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question