This give you some example for scanning files with specified string or specified file type from your pointed folder directory. you can scan the files and copy them to a temporary folder, also you can merge them together into one file. [java] package com_2013; import java. io. *; import java. util. *; public class FileScan {static String fromdir = "Input the folder directory where you need to scan the f Iles. "; static String todir =" Input the folder directory where you need copy the scanned files. "; static String findstr =" Input the string that is specified scanned condition. "; static String targetFileName =" D:/targetFileName. SQL "; static String filetype = ". SQL "; static int filenum = 1; static File outFile; static RandomAccessFile outt; public static void main (String [] args) {File filedir = New File (fromdir); FileScan FS = new FileScan (); // Function 1: Scan the files and copy them to a folder. // File toDir = new File (todir); // if (! ToDir. isDirectory () {// toDir. mkdirs (); //} // FS. fileScan (filedir); // Function 2: Scan the files and merge them into one file. try {outFile = new File (targetFileName); if (! OutFile. exists () outFile. createNewFile (); outt = new RandomAccessFile (outFile, "rw"); FS. fileScanUnite (filedir); outt. close ();} catch (Exception e) {e. printStackTrace () ;}} public FileScan () {}/ *** Scan the specified files from the specified folder and unite them together into one file. * @ param fileDir */public void fileScanUnite (File fileDir) throws Exception {File [] file = fileDir. listFi Les (); for (int I = 0; I <file. length; I ++) {File subfile = file [I]; if (subfile. isDirectory () {fileScanUnite (subfile);} else {String temp = subfile. getName (). toUpperCase (); if (temp. indexOf (findstr. toUpperCase ()> 0 & temp. endsWith (filetype. toUpperCase () {RandomAccessFile inn = new RandomAccessFile (subfile, "r"); int c; while (c = inn. read ())! =-1) outt. write (c); System. out. println ("Merge file:" + subfile. getPath () ;}}}/*** Scan the files from the specified folder * @ param filedir */public void fileScan (File filedir) {File [] file = filedir. listFiles (); for (int I = 0; I <file. length; I ++) {File subfile = file [I]; if (subfile. isDirectory () {fileScan (subfile);} else {String temp = subfile. getName (). toUpperCase (); if (temp. indexOf (findstr. toUpperCase ()> 0 & temp. endsWith (filetype. toUpperCase () {try {fileCopy (subfile, new File (todir + findstr + "_" + String. valueOf (filenum ++) + filetype);} catch (Exception e) {e. printStackTrace ();} finally {System. out. println ("Copy file:" + subfile. getPath ());}}}}} /*** Copy the file from f1 to f2sa * @ param f1 * @ param f2 * @ return * @ throws Exception */public long fileCopy (File f1, File f2) throws Exception {long time = new Date (). getTime (); int length = 2097152; FileInputStream in = new FileInputStream (f1); FileOutputStream out = new FileOutputStream (f2); byte [] buffer = new byte [length]; while (true) {int ins = in. read (buffer); if (ins =-1) {in. close (); out. flush (); out. close (); return new Date (). getTime ()-time;} else out. write (buffer, 0, ins );}}}