0

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

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

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

代码:

    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();
    }

请帮我解决这个问题?

4

3 回答 3

1

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

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

\\\\wastServer\\apps\\

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

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

于 2013-01-30T04:58:05.627 回答
0

您没有对共享、目录之一或文件本身的写入权限。可能该文件已经打开。

于 2013-01-30T07:33:48.387 回答
-1

在这条线之后

 File fo = new File(FilePath);

尝试打印绝对路径

System.out.println( fo.getAbsolutePath() );

然后检查文件是否存在于该位置,而不是直接检查

\\\\wastServer\\apps\\LogPath\\message.txt

因此,您将知道编译器在哪里搜索文件。

于 2013-01-30T05:19:50.967 回答