Copying files from one directory to another in Java

Posted by user42155 on Stack Overflow See other posts from Stack Overflow or by user42155
Published on 2009-07-17T23:38:43Z Indexed on 2011/01/07 6:53 UTC
Read the original article Hit count: 198

Filed under:
|
|
|

Hello,

I want to copy files from one directory to another (subdirectory) using Java. I have a directory, dir, with text files. I iterate over the first 20 files in dir, and want to copy them to another directory in the dir directory, which I have created right before the iteration. In the code, I want to copy the review (which represents the ith text file or review) to trainingDir. How can I do this? There seems not to be such a function (or I couldn't find). Thank you.

boolean success = false;
File[] reviews = dir.listFiles();
String trainingDir = dir.getAbsolutePath() + "/trainingData";
File trDir = new File(trainingDir);
success = trDir.mkdir();
for(int i = 1; i <= 20; i++) {
    File review = reviews[i];

}

© Stack Overflow or respective owner

Related posts about java

Related posts about file