導航:首頁 > 文件教程 > 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寫文件相關的資料

熱點內容
網路中常用的傳輸介質 瀏覽:518
文件如何使用 瀏覽:322
同步推密碼找回 瀏覽:865
樂高怎麼才能用電腦編程序 瀏覽:65
本機qq文件為什麼找不到 瀏覽:264
安卓qq空間免升級 瀏覽:490
linux如何刪除模塊驅動程序 瀏覽:193
at89c51c程序 瀏覽:329
怎麼創建word大綱文件 瀏覽:622
裊裊朗誦文件生成器 瀏覽:626
1054件文件是多少gb 瀏覽:371
高州禁養區內能養豬多少頭的文件 瀏覽:927
win8ico文件 瀏覽:949
仁和數控怎麼編程 瀏覽:381
項目文件夾圖片 瀏覽:87
怎麼在東芝電視安裝app 瀏覽:954
plc顯示數字怎麼編程 瀏覽:439
如何辨別假網站 瀏覽:711
寬頻用別人的賬號密碼 瀏覽:556
新app如何佔有市場 瀏覽:42

友情鏈接