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 have the following code to print a string(from a ResultSet) to a text file:

PrintWriter writer = new PrintWriter(new FileOutputStream(file, false));
while(RS.next()) {
    writer.write(RS.getString(1)+"
");
}

I put a " " in the write statement in hopes that it will print each row on a different line, but it failed. The txt file currently prints out like so, with row# being a different row in the ResultSet:

row1row2row3row4row5

I want it to print out like:

row1

row2

row3

row4

row5

...

See Question&Answers more detail:os

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

1 Answer

You should use println to print a newline character after each line:

writer.println(RS.getString(1));

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

548k questions

547k answers

4 comments

86.3k users

...