1

所以,我正在编写 FTP 服务器客户端,但代码无法读取任何文件。我是说。我在下载有一个文件。假设 /Downloads/supplement2.pdf 但我得到一个 FileNotFoundException。即使文件在那里,我可以看到它。我什至创建了一个测试文件夹并将其权限设置为 777。仍然没有。

有没有办法设置netbeans作为超级用户做什么?我是说。我只想复制和粘贴一些东西,但不能。这是复制和粘贴代码。如果您发现它有任何问题,请分享。

 public static void copyFile(File in, File out)
        throws IOException
    {
        FileChannel inChannel = new
            FileInputStream(in).getChannel();
        FileChannel outChannel = new
            FileOutputStream(out).getChannel();
        try {
            inChannel.transferTo(0, inChannel.size(),
                    outChannel);
        }
        catch (IOException e) {
            throw e;
        }
        finally {
            if (inChannel != null) inChannel.close();
            if (outChannel != null) outChannel.close();
        }
    }

谢谢

4

3 回答 3

2

您是否指定了文件的正确路径?

您可以尝试指定完整路径或将文件放在与代码相同的目录中。

于 2010-01-23T22:23:27.803 回答
1

尝试创建一个具有不寻常名称的新文件,向其中写入一些内容,然后在文件系统中找到该文件。

于 2010-01-23T22:27:37.937 回答
0

我粘贴并调用了您的代码

copyFile(new File("C:/TEMP/Folder1/test.txt"), 
         new File("C:/TEMP/Folder2/test.txt"));

虽然只有文件夹 1 中的文件存在并且 - 是的,它有效。完整的堆栈跟踪可能会有所帮助。源路径或目标路径中的任何文件夹或文档是挂载还是链接?

于 2010-01-23T23:20:25.883 回答