ileWriter时出现FileNotFoundExceptio

ileWriter时出现FileNotFoundExceptio

本文介绍了使用FileWriter时出现FileNotFoundException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将一些消息写入文本文件。文本文件位于服务器路径中。我能够从该文件中读取内容。但是我无法将内容写入该文件。我收到FileNotFoundException:\ wastServer \apps \ LogPath \message.txt(拒绝访问)。

I am trying to write some message to text file. The text file is in the server path. I am able to read content from that file. But i am unable to write content to that file. I am getting FileNotFoundException: \wastServer\apps\LogPath\message.txt (Access Denied).

注意:文件具有读写权限。

Note: File has a read and write permissions.

但我在做错了。请在下面找到我的代码。

But where i am doing wrong. Please find my code below.

代码:

    String FilePath = "\\\\wastServer\\apps\\LogPath\\message.txt";

    try {
        File fo = new File(FilePath);
        FileWriter fw=new FileWriter(fo);
        BufferedWriter bw=new BufferedWriter(fw);
        bw.write("Hello World");
        bw.flush();
        bw.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

请帮帮我吗?

推荐答案

请检查您是否可以访问 apps LogPath 目录。

Please check whether you can access the apps and LogPath directory.

在运行时键入这些(Windows键+ R)

Type these on Run (Windows Key + R)

\\\\wastServer\\apps\\

\\\\wastServer\\apps\\LogPath\\

并查看您是否可以从执行上述代码的计算机和用户访问这些目录。

And see whether you can access those directories from the machine and user you are executing the above code.

这篇关于使用FileWriter时出现FileNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 02:09