更新時(shí)間:2022-10-19 11:00:57 來(lái)源:動(dòng)力節(jié)點(diǎn) 瀏覽5469次
java中寫(xiě).txt文件,實(shí)現(xiàn)換行的幾種方法:
1.使用java中的轉(zhuǎn)義符"/r/n":
String str="aaa";
str+="/r/n";
這樣在str后面就有換行了.
注意:/r,/n的順序是不能夠?qū)Q的,否則不能實(shí)現(xiàn)換行的效果.
2.BufferedWriter的newline()方法:
FileOutputStream fos=new FileOutputStream("c;//11.txt");
BufferedWriter bw=new BufferedWriter(fos);
bw.write("你好");
bw.newline();
bw.write("java");
bw.newline();
3.使用System.getProperty()方法:
String str = "aaa"+System.getProperty("line.separator");
相關(guān)閱讀
0基礎(chǔ) 0學(xué)費(fèi) 15天面授
有基礎(chǔ) 直達(dá)就業(yè)
業(yè)余時(shí)間 高薪轉(zhuǎn)行
工作1~3年,加薪神器
工作3~5年,晉升架構(gòu)
提交申請(qǐng)后,顧問(wèn)老師會(huì)電話與您溝通安排學(xué)習(xí)
初級(jí) 202925
初級(jí) 203221
初級(jí) 202629
初級(jí) 203743