views:

163

answers:

3

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

+2  A: 

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.

ddccffvv
What I want to do is copy-paste the file from/to the local Netbeans folder and yes the folder is absolutely right. I thinks the problem is about the restrictions from java that I have to somewhat to lift or something.
Kevin_Jim
Java is normally started with the same rights as you have. If it was a file restrictions problem, you would probably get something like "FileNotFound exception (Access Denied)"
ddccffvv
+1  A: 

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

Skip Head
A: 

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?

Andreas_D