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

熱點內容
第31次中國互聯網路發展狀況調查統計報告 瀏覽:835
蘋果4s打不開appstore 瀏覽:452
java顏色lei 瀏覽:843
文件咋能保存到桌面 瀏覽:242
潮汐app圖片在哪裡 瀏覽:314
文獻期刊是哪個資料庫 瀏覽:956
機械加工教程 瀏覽:896
字元串asciijava 瀏覽:516
不存在的文件夾 瀏覽:954
js給url追加參數 瀏覽:618
如何存取文件 瀏覽:340
js獲取樣式名稱 瀏覽:543
寬頻數據功能在電視哪個系統找到 瀏覽:427
計算機程序ui設計員是什麼 瀏覽:346
文件拖動到ps圖層 瀏覽:802
數據類型是雙位元組型有哪些 瀏覽:990
可以使用什麼對象更新資料庫 瀏覽:703
怎麼編程加工數字 瀏覽:992
寫的小說投哪個網站好 瀏覽:984
js日期隨機數 瀏覽:630

友情鏈接