2015年4月11日 星期六

#JAVA change line in txt

I tried to write string to txt file in java .
When i checked my txt file in my windows,i encountered some problems.
If i use \n to change a new line ,i saw some black block appear the position that should change line and change line doesn’t work at all.
But when i use my android device to check the result ,it’s ok!!!
It’s wired,but i found a way to solve it.

answer:
use \r\n instead of using \n and the txt file you open on you pc will be ok :")


如果單純用\n來換行,用記事本打開檔案時
會看到原本應該換行的地方變成很多黑色小方塊
而且每行會接在一起,看起來很奇怪
不過用Java讀取這個文字檔時卻又是正常的
解決法很簡單,只要在\n前面加上\r
變成"\r\n",在記事本上看就不會亂掉了

沒有留言:

張貼留言