epub, HTML, txt files in the Java Replication folder (stored in the original folder)

Source: Internet
Author: User
Tags file copy

Files in the original folder: Epub/html/txt





Import Java.io.file;import Java.io.fileinputstream;import Java.io.filenotfoundexception;import Java.io.fileoutputstream;import java.io.ioexception;/** * Copy all files in the folder that contain the. epub Suffix * @author fibre * Parameter SUFFIX = ". Epu B "*/public class Copyfilefolder {private static String SUFFIX =". epub ";p ublic void CopyFolder (String folder, String NEWP Ath) throws ioexception{file old = new File (folder); file[] Filearray = Old.listfiles (); for (File File:filearray) {if (File.isfile ()) {if (File.getname (). EndsWith (SUFFIX)) { Determine if the destination folder File newpathfile = new File (NewPath), if (!newpathfile.isdirectory ()) {newpathfile.mkdirs ();} Start copying try {fileinputstream ins = new FileInputStream (file); FileOutputStream out = new FileOutputStream (newpath+ "/" +file.getname ()); SYSTEM.OUT.PRINTLN ("!! File copy: "+file.getabsolutepath () +"-----> "+newpath+"/"+file.getname ()); byte[] B = new byte[1024 * 5];int Len;while (( Len=ins.read (b))! =-1) {out.write (b);} Ins.close (); Out.close ();} catch (FileNotFoundException e) {//TODO auto-generated CatCH Blocke.printstacktrace ();}}} if (File.isdirectory ()) {CopyFolder (File.getabsolutepath (), newpath+ "/" +file.getname ()); System.out.println ("" Folder Copy ":" +file.getabsolutepath () + "----->" +newpath+ "/" +file.getname ())}}} public static void Main (string[] arg) throws ioexception{//can be changed to copy a file with a suffix of html//copyfilefolder.suffix = ". htm L "; String folder = "f://resource/to/epub/know each professional answer collection"; String target = "f://resource//epub/know each Professional answer collection (epub)"; Copyfilefolder copy = new Copyfilefolder (); Copy.copyfolder (Folder,target);}}

after execution: store by folder, only epub file







Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.