A Java program that copies only files that do not copy folders

Source: Internet
Author: User

Import Java.io.file;import java.io.fileinputstream;import java.io.fileoutputstream;import java.io.IOException; Import Java.io.inputstream;import Java.io.outputstream;public class Deepcopy {public static void main (string[] args) { Deepcopy ("F:/software/All Fonts", "F:/software/all_font");} Copy all Folder_source files (excluding folders) to dest_folder,private static void Deepcopy (String folder_source, String dest_folder) { File File1 = new file (Folder_source), if (File1.isfile ()) {copy (File1.getabsolutepath (), dest_folder+ "/" +file1.getname ());} else if (file1.isdirectory ()) {file[] Files2 = File1.listfiles (); for (int i = 0; i < files2.length; i++) {deepcopy (files2 [I].getabsolutepath (), Dest_folder);}}} public static Boolean copy (String Filefrom, String fileto) {try {inputstream in = new FileInputStream (filefrom); outputstre Am out = new FileOutputStream (fileto); byte[] bt = new Byte[1024];int Count;while ((count = In.read (BT)) > 0) {out.write (BT, 0, Count);} In.close (); Out.close (); System.out.println ("Copy finished!");return true;} catch (IOException ex) {ex.printstacktrace (); return false;}}}

A Java program that copies only files that do not copy folders

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.