简体   繁体   中英

Unexpected line break using PrintWriter

I don't know why PrintWriter break the line when it see this symbol '##'

I want to write these line to .txt file

系统数据

But got this, you can see it got some unexpected rows:

使用 Printwriter 后的结果

Part of my code:

try(OutputStreamWriter fw = new OutputStreamWriter(
                                            new FileOutputStream(filePath + "\\" +file_number + "_"+ info.getFileName(), true),
                                            StandardCharsets.UTF_8);
                                            BufferedWriter bw = new BufferedWriter(fw);
                                            PrintWriter out = new PrintWriter(bw, false)) {
       JCoTable rows = function6.getTableParameterList().getTable("DATA");
       for (int i = 0; i < rows.getNumRows(); i++) {
          rows.setRow(i);
          out.write(Integer.toString(CURRENT_ROW) + ((char)Integer.parseInt(info.getFileDelimited()))+ rows.getString("WA") + "\n");}

The ABAP table contains 6 rows and your output contains 6 rows. So I guess you mean with "additional rows" the 2 additional line breaks in rows no. 2 and 6.

I assume this is because these line breaks are part of the text in these rows. The SAP GUI doesn't write these control characters and outputs them as '##', but the Java code prints these characters, of course. I guess these 2 substituted chars '##' actually are the control characters END OF LINE (U+000A) and CARRIAGE RETURN (U+000D). You can check their real character codes with the ABAP debugger's hexadecimal view or in your Java development environment debugger.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM