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

熱點內容
精銳網吧管理輔助工具 瀏覽:792
網路盒上的線應該怎麼插 瀏覽:700
cad打開第二個文件時出現致命錯誤 瀏覽:917
java和python表情包 瀏覽:697
計算機編程為什麼很容易改行 瀏覽:797
編程解方程用什麼軟體 瀏覽:302
如何將文件傳給微信 瀏覽:877
app緩存文件該存在哪裡 瀏覽:793
jscss載入器 瀏覽:822
qq瀏覽器下載視頻文件源錯誤 瀏覽:196
6splus文件描述在哪裡 瀏覽:832
windows文件如何插入圖片 瀏覽:681
安卓蘋果開機圖片 瀏覽:80
下載的qq群文件沒了 瀏覽:813
word2003頁碼從任意頁開始 瀏覽:723
matlab保存數據excel文件 瀏覽:513
哪個app可以看免費短篇小說 瀏覽:714
視覺設計有哪些數據分析能力 瀏覽:554
word紙張沒有a4 瀏覽:499
小波去噪matlab程序 瀏覽:345

友情鏈接