user682765
user682765

Reputation: 1229

File Not found exception

I have a bunch of files in a folder checked out from a repository. I have a code which has to copy the files from the folder to another folder. I do the following:

File f = new File(/* path of folder */);
File[] fs = f.listFiles();
for(int i=0; i<fs.length; i++){
        FileChannel in = new FileInputStream(fs[i]).getChannel();
        FileChannel out = new FileOutputStream(/* output directory */ +File.separatorChar+files[i].getName()).getChannel();
        in.transferTo(0, in.size(), out);
}

However, the .svn file within the checked out directory is causing a problem. I get the exception:

java.io.FileNotFoundException: /checked_out_folder/.svn (No such file or directory)
[x]     at java.io.FileInputStream.open(Native Method)
[x]     at java.io.FileInputStream.<init>(FileInputStream.java:120)

Is it because it is a hidden file? What could be the solution for this? Or am I missing something here? Thanks

Upvotes: 1

Views: 2298

Answers (1)

room13
room13

Reputation: 1922

I think it is because it is a directory and not a file.

Directories you have to create by using the mkdir method. Whole directories cannot be copied in java as far as I know.

For an example on how to copy a directoy, see this blog post.

Upvotes: 5

Related Questions