代碼如下: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);
}
}
}
添加回答
舉報
0/150
提交
取消