为了账号安全,请及时绑定邮箱和手机立即绑定

想咨询一下关于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 关注
  • 123 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信