S
S
Sergey Khlopov2020-02-24 14:28:54
Java
Sergey Khlopov, 2020-02-24 14:28:54

How to remove the empty line at the end when writing to a file?

Hello, please tell me, I have the following code:

PrintWriter out = new PrintWriter("files/out.txt");
     for(String email : result) {
         out.println(email);
       }
 out.close();

The output to the file looks like this:
5e53b32a8938d451471503.png
How do I remove the last empty line? Thank you in advance for your response.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
antonwx, 2020-02-24
@Shlop

use print instead of println. The latter adds a line break after text output automatically. Add a break \n (or \r\n for windows format) manually at the end of lines, except for the last one.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question