程序看不到文件,但它存在。文件未找到异常

发布于 2024-08-19 03:54:25 字数 847 浏览 3 评论 0原文

因此,我正在编写 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();
        }
    }

谢谢

So, I'm writing FTP server-client but the code can't read any file. I mean. I have a file at Downloads. Let's say /Downloads/supplement2.pdf but I get a FileNotFoundException. Even though the file is there and I can see it. I even made a test folder and set it's privilages to 777. Still, nothing.

Is there a way to set what netbeans does as superuser or something? I mean. I just want to copy and paste something but can't. Here's the copy and paste code. If you see anything wrong with it please share.

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

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

浅紫色的梦幻 2024-08-26 03:54:25

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

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

Are you specifying the right path to the file?

You can try specifying the full path or placing a file in the same directory as the code.

明媚如初 2024-08-26 03:54:25

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

Try just creating a new file with an unusual name, writing something to it and then finding the file in your file system.

吲‖鸣 2024-08-26 03:54:25

我粘贴并调用了您的代码,

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

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

I pasted and called your code with

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

while only file in folder 1 existed and - yes, it worked. A complete stack trace could be helpful. Is any folder or document in the source or target path a mount or a link?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文