Here you can find the source of fileCopy(String sourceFolder, String destinationFolder)
Parameter | Description |
---|---|
sourceFolder | a parameter |
destinationFolder | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static void fileCopy(String sourceFolder, String destinationFolder) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FileFilter; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.nio.channels.FileChannel; public class Main { /**/*from w w w .ja v a2 s .c om*/ * Copies all the files from the source folder to the destination folder. * * @param sourceFolder * @param destinationFolder * @throws IOException */ public static void fileCopy(String sourceFolder, String destinationFolder) throws IOException { File source = new File(sourceFolder); FileFilter filter = new FileFilter() { @Override public boolean accept(File pathname) { if (pathname.isFile()) { if (pathname.getName().indexOf("jpg") != -1 || pathname.getName().indexOf("jpeg") != -1 || pathname.getName().indexOf("png") != -1) return true; } return false; } }; File[] files = source.listFiles(filter); for (File file : files) { FileChannel fIn = new FileInputStream(file).getChannel(); FileChannel fOut = new FileOutputStream(new File(destinationFolder + file.getName())).getChannel(); fIn.transferTo(0, fIn.size(), fOut); } } }