java输出流 拒绝访问_java – 使用FileOutputStream时拒绝访问

在尝试使用FileOutputStream将字符串写入C:\WeatherExports\export.txt时,遇到了'Access is denied'的错误。代码尝试创建文件并追加信息,但遇到了权限问题。错误堆栈追踪显示问题出现在FileOutputStream的构造函数中。
摘要由CSDN通过智能技术生成

我有一个问题让这个工作.它包含一个由几条信息组成的字符串.

但是,当我尝试将String写入文件以便跟踪程序随时间的变化时,我收到一个拒绝访问错误:

void writeToFile(String input) throws Exception{

File file = new File("C:\\WeatherExports\\export.txt");

if(!file.exists()){

file.createNewFile();

}

BufferedWriter inFile = new BufferedWriter(new FileWriter(file,true));

try{

inFile.append(input);

inFile.newLine();

} catch(Exception e){

e.printStackTrace();

}

inFile.close();

}

STACKTRACE YEILDS:

java.io.FileNotFoundException: C:\WeatherExports\export.txt (Access is denied)

完整Stacktrace:

java.io.FileNotFoundException: C:\WeatherExports\export.txt (Access is denied)

at java.io.FileOutputStream.openAppend(Native Method)

at java.io.FileOutputStream.(Unknown Source)

at ja

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值