I have files in one folder, i want to move them into the another folder but also and to rename them (with some static prefix value which should be added)
I succeed to list all files from the source directory but I cannot find move
method when getting files[i]
and I also cannot find how to rename and move files to another folder in the same time.
Can someone tell me what I should add in getFiles
method in order to move and rename.
This is my class.
import java.io.File;
public class CopyTest {
static File mainFolder = new File("F:\\TestCopy");
static File destinationFolder = new File("F:\\TestCopy2");
public String prefix="PREFIX";
public static void main(String[] args)
{
CopyTest lf = new CopyTest();
lf.getFiles(lf.mainFolder);
long fileSize = mainFolder.length();
System.out.println("File size in KB is : " + (double)fileSize/1024);
}
public void getFiles(File f){
File files[];
if(f.isFile())
System.out.println(f.getAbsolutePath());
else{
files = f.listFiles();
for (int i = 0; i < files.length; i++) {
getFiles(files[i]);
}
}
}
}