Friday, 15 June 2012

Program which copies files of specified extension to new folder and all files to other folder use the following jar file commons-io-2.3


Program which copies files of specified extension to new folder and all files to other folder use the following jar file commons-io-2.3


package com.demo;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.apache.commons.io.FileUtils;

public class CopyFile {

static List<File> filelist = new ArrayList<File>();

public static void main(String[] args) {

File f1 = new File("c:/javasamples");
Collection<File> files = FileUtils.listFiles(f1,
new String[] { "class" }, true);
for (File str : files) {
System.out.println("files are " + str);
if (!filelist.contains(str)) {
filelist.add(str);
}

}
for (File str : filelist) {
System.out.println("new list " + str);

File destDir;
destDir = new File("c:/newfolder");


try {
FileUtils.copyFileToDirectory(str, destDir);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
File destdir;
destdir = new File("c:/copy");
try {
FileUtils.copyDirectory(f1, destdir);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

}

No comments:

Post a Comment

Pass a HashMap from Angular Client to Spring boot API

This example is for the case where fileData is very huge and in json format   let map = new Map<string, string>()      map.set(this.ge...