Java:stringbuilder Append line break problem

Source: Internet
Author: User

There are several lines of code in the IO operation:

while (line = Bufferedreader.readline ())!=null) {
if (Line.length ()! = 0) {
Stringbuilder.append (line+ "\ r \ n");
}
}

Here the line break "\ r \ n" fails, replacing it with "\ n" is not possible, and finally replaced with the JDK's own cross-platform line delimiter, the program is rewritten as follows:
Stringbuilder.append (Line+system.getproperty (line.separator));

Problem solving.
In addition, "\ r \ n", \ r is the carriage return (return?) ), back to the beginning of the line, \ n is newline (next?) ), move the cursor to the same horizontal position of the next line.
The impression of the keyboard on the Enter is called carriage return, can be wrapped, Java programming language is not the case.
In Linux \ n contains a carriage return, Windows does not, the lack of control or the order of the wrong will be invalidated, of course, the reason for failure is more than two.
There is also a case where the row delimiter is invalid, and you can replace the two line breaks to try again. The reason may be that there is a difference between the server that the code is deployed on and the system that the user uses
For example, projects are often deployed on Linux, and most users are using Windows. "System.getproperty (Line.separator)" As a cross-platform delimiter,
Automatically gets the new line character under Linux \ n, which is invalidated under Windows. You need to change the cross-platform delimiter to \ r \ n, that is, consistent with the system used by the user.





Java:stringbuilder Append line break problem

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.