weixin_40653242
weixin_40653242
2017-10-17 15:16

为什么我的FilOutputStream对象不能自动创建文件

  • java

public static void writeGBK() throws IOException{
//创建字节输出流,绑定数据文件
FileOutputStream fos = new FileOutputStream("c:\gbk.txt");
//创建转换流对象,使用构造方法,绑定字节输出流,使用GBK
OutputStreamWriter osw = new OutputStreamWriter(fos);
//转换流写数据
osw.write("你好");

osw.close();

}

异常信息:
Exception in thread "main" java.io.FileNotFoundException: c:\gbk.txt (拒绝访问。)
at java.io.FileOutputStream.open0(Native Method)
at java.io.FileOutputStream.open(FileOutputStream.java:270)
at java.io.FileOutputStream.(FileOutputStream.java:213)
at java.io.FileOutputStream.(FileOutputStream.java:101)
at demo_1.OutputStreamWriterDemo_1.writeGBK(OutputStreamWriterDemo_1.java:28)
at demo_1.OutputStreamWriterDemo_1.main(OutputStreamWriterDemo_1.java:19)

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

3条回答