2011-08-12 148 views
0

我需要通過TCP連接寫入的字符串有\n\r個字符。這些字符正在打印爲\\n\\r。我該如何解決這個問題?將 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轉義序列性格特徵)值。

+2

你是如何獲得輸出的?這是你在TCP連接另一端得到的嗎?我假設'outputStream'實際上是一個'SocketOutputStream'? –

+0

不應將字符串替換爲額外的轉義序列。我們能做到這一點嗎 – gmeka

+0

爲什麼不在收到控制字符後將其轉換回所需的輸出? –

回答

0

你試過逃脫嗎?

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

這會讓事情變得更糟!顯然系統中的某些東西已經在做這件事。 – EJP