1

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

Kevin
  • 561
  • 1
  • 7
  • 20
  • you're not in a chroot, are you? – bmargulies Jan 23 '10 at 22:26
  • Out of interest, are you writing this as a programming exercise? (... because otherwise there are numerous Java FTP library implementations you could use). – Adamski Jan 23 '10 at 22:29
  • 1
    Just for clarification - do you get the FNFE for the input file, the target folder or the target file? – Andreas Dolk Jan 23 '10 at 22:32
  • SO is eating comments - the comment that Kevin_Jim replied to contained the link: http://stackoverflow.com/questions/486494/filenotfoundexception-thrown-when-the-file-does-exists – Andreas Dolk Jan 23 '10 at 23:09
  • @Kevin - for sure, at least it's a similar problem and - I assume you used Search before asking ;-) - Just kidding - the other problem was caused by missing user access rights for the application. – Andreas Dolk Jan 23 '10 at 23:11

3 Answers3

2

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
  • 144
  • 3
  • 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 Jan 23 '10 at 22:26
  • 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 Jan 23 '10 at 23:09
1

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
  • 7,580
  • 1
  • 30
  • 34
0

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 Dolk
  • 113,398
  • 19
  • 180
  • 268