有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java写入输出流\r

我需要通过TCP连接写入的字符串有\n\r个字符。这些字符打印为\\n\\r。我怎样才能解决这个问题

String myLine = "this is first line\r this is second line\r third line";
outputStream.write(myLine);

结果:

this is first line\\r this is second line\\r third line

但我需要编写与myLine(只有1个转义序列字符)值相同的结果


共 (1) 个答案

  1. # 1 楼答案

    你试过逃避吗

    "this is first line\\\\r this is second line\\\\r third line"