java輸入回車則結(jié)束輸入 JAVA輸出內(nèi)容打印到TXT以及不同系統(tǒng)中如何換行?
JAVA輸出內(nèi)容打印到TXT以及不同系統(tǒng)中如何換行?java中寫.txt文件,實現(xiàn)換行的幾種方法:1.使用java中的轉(zhuǎn)義符"rn":Java代碼 String str="aaa" str ="
JAVA輸出內(nèi)容打印到TXT以及不同系統(tǒng)中如何換行?
java中寫.txt文件,實現(xiàn)換行的幾種方法:
1.使用java中的轉(zhuǎn)義符"rn":
Java代碼
String str="aaa"
str ="rn"
String str="aaa"
str ="rn"
這樣在str后面就有換行了.
注意:r,n的順序是不能夠?qū)Q的,否則不能實現(xiàn)換行的效果.
2.BufferedWriter的newline()方法:
Java代碼
FileOutputStream fos=new FileOutputStream("c11.txt")
BufferedWriter bw=new BufferedWriter(fos)
bw.write("你好")
bw.newline()
bw.write("java")
w.newline()
FileOutputStream fos=new FileOutputStream("c11.txt")
BufferedWriter bw=new BufferedWriter(fos)
bw.write("你好")
bw.newline()
bw.write("java")
bw.newline()
3.使用System.getProperty()方法:
Java代碼
String str = "aaa" System.getProperty("line.separator")
String str = "aaa" System.getProperty("line.separator")