導航:首頁 > 文件教程 > javastring寫文件

javastring寫文件

發布時間:2025-06-18 01:54:50

java 寫txt文件

import java.io.*;
public class Test {

public static void main(String[] args){
String s = new String();
String s1 = new String();
try {
File f = new File("E:\\123.txt");
if(f.exists()){
System.out.print("文件存在");
}else{
System.out.print("文件不存在");
f.createNewFile();//不存在則創建
}
BufferedReader input = new BufferedReader(new FileReader(f));

while((s = input.readLine())!=null){
s1 += s+"\n";
}
System.out.println(s1);
input.close();
s1 += "添加的內容!";

BufferedWriter output = new BufferedWriter(new FileWriter(f));
output.write(s1);
output.close();
} catch (Exception e) {
e.printStackTrace();
}
}

}

② java 怎麼將數據寫入TXT文件

import java.io.FileWriter;
import java.io.IOException;

public class Test02 {

void writefile() throws IOException {
FileWriter fileWriter=new FileWriter("c:\\Result.txt");
int [] a=new int[]{111,222,333,444,555,666};
for (int i = 0; i < a.length; i++) {
fileWriter.write(String.valueOf(a[i])+" ");

}
fileWriter.flush();
fileWriter.close();
}
public static void main(String[] args) throws IOException {
new Test02().writefile();
}
}
//你看來看,就這源兩句,測試通過了!

③ java 語言中如何實現 寫文件 換行。。謝謝了!!

1.\r\n就是換行了

2.然後就是樓上說的BufferedWriter的newline了

3. System.getProperty("line.separator");
給個例子給你吧
.....
1.
String s = "aaa";
s += "aaa"+"\r\n";

這樣,在s之後就有換行了
2.略
3. String s = "aaa"+System.getProperty("line.separator");

閱讀全文

與javastring寫文件相關的資料

熱點內容
如何將xml導入資料庫 瀏覽:395
編程和英語哪個好 瀏覽:474
網店編程軟體有哪些 瀏覽:196
真假的蘋果手機對比圖片 瀏覽:503
彩電內存數據用什麼軟體 瀏覽:975
計算機網路課本 瀏覽:486
大數據書的結構是什麼 瀏覽:409
蘋果7手機代碼查詢步驟 瀏覽:372
如何辦理網路教育 瀏覽:643
ps保存文件亂碼了 瀏覽:23
電腦傳文件到手機一會停止 瀏覽:363
怎麼把word保存為pdf文件 瀏覽:803
怎麼恢復備份文件小米 瀏覽:620
年齡大適合學什麼編程語言 瀏覽:201
榮耀9文件夾怎麼改名字 瀏覽:113
奔跑吧哪個app可以看 瀏覽:646
做教研的數據哪裡找 瀏覽:162
怎樣復制到u盤文件夾里 瀏覽:53
淘寶網上怎麼投訴app軟體 瀏覽:900
u盤刪除ppt文件如何恢復 瀏覽:487

友情鏈接