亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

想咨詢一下關于FileOutputStream的問題,麻煩大佬幫忙看看~

想咨詢一下關于FileOutputStream的問題,麻煩大佬幫忙看看~

函數式編程 2022-01-06 20:07:20
代碼如下:Properties props = new Properties();InputStream is = getClass().getResourceAsStream("test.properties");try{props.load(is);is.close();System.out.println(props.getProperty("test"));props.setProperty("test", "reset");FileOutputStream fos = new FileOutputStream("test2",true);props.store(fos, null);fos.write("httpL//juncsu.blogcn.com".getBytes());fos.close();}catch(Exception ex){ex.printStackTrace();}結果是屬性文件的內容可以讀出來,但是無法寫進去,測試中FileOutputStream直接寫入也沒有反應。不知道什么情況會導致這樣的問題?或者有其他寫Properties的方法?
查看完整描述

2 回答

?
慕桂英3389331

TA貢獻2036條經驗 獲得超8個贊

/**
* 讀出1.txt中的內容,寫入2.txt中
*
*/

import java.io.*;

public class readwritefile{
public static void main(string[] args){
try{

file read = new file("c:\\1.txt");
file write = new file("c:\\2.txt");

bufferedreader br = new bufferedreader(
new filereader(read));
bufferedwriter bw = new bufferedwriter(
new filewriter(write));
string temp = null;
temp = br.readline();
while(temp != null){
//寫文件
bw.write(temp + "\r\n"); //只適用windows系統
//繼續讀文件
temp = br.readline();
}

bw.close();
br.close();

}catch(filenotfoundexception e){ //文件未找到
system.out.println (e);
}catch(ioexception e){
system.out.println (e);
}
}
}

 


查看完整回答
反對 回復 2022-01-10
?
慕后森

TA貢獻1802條經驗 獲得超5個贊

FileOutputStream fos = new FileOutputStream("test2",true);
test2文件沒有擴展名

查看完整回答
反對 回復 2022-01-10
  • 2 回答
  • 0 關注
  • 159 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號