程序看不到文件,但它存在。文件未找到异常
因此,我正在编写 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是否指定了正确的文件路径?
您可以尝试指定完整路径或将文件放置在与代码相同的目录中。
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.
尝试创建一个具有不寻常名称的新文件,向其中写入一些内容,然后在文件系统中查找该文件。
Try just creating a new file with an unusual name, writing something to it and then finding the file in your file system.
我粘贴并调用了您的代码,
同时仅存在文件夹 1 中的文件 - 是的,它有效。完整的堆栈跟踪可能会有所帮助。源或目标路径中的任何文件夹或文档是否是挂载或链接?
I pasted and called your code with
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?