Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I would like the following to be printed

test1

test2

test3

test4

But I can't seem to get the text to the next line.

Please help

import java.io.*;

public class MainFrame {
    public static void main(String[] args) {
        try {
        BufferedWriter out = new BufferedWriter(new FileWriter("file.txt"));
            for (int i = 0; i < 4; i++) {
                out.write("test " + "
");
            }
            out.close();
        } catch (IOException e) {}
    }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
256 views
Welcome To Ask or Share your Answers For Others

1 Answer

Try out.newLine();

So, it would be

for (int i = 0; i < 4; i++) {
    out.write("test " + "
");
    out.newLine();
}

Source (Java API)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...