Write a program to copy all the. java files under the D:\java directory to the D:\jad directory and change the original file's extension from. java to. jad.

Source: Internet
Author: User

Package Io;import java.io.*;p ublic class FileCopy {public static void main (string[] args) throws exception{file Srcdir = n EW File ("Java"); Srcdir.isdirectory () && srcdir.exists ()) {throw new Exception ("directory does not Exist");} String[] list,file[] Listfiles method can receive a filenamefilter parameter, the//filenamefilter interface contains an accept (File dir,string name) method,// The method iterates through all subdirectories or files of the specified file, if the method returns True or false/*file[] files = srcdir.listfiles (new FilenameFilter () {public boolean Accept (File dir, String name) {return Name.endswith (". Java");}}); */file[] files = Srcdir.listfiles ((dir, name), Name.endswith (". Java")); File DestDir = new file ("Jad"), if (!destdir.exists ()) {Destdir.mkdir ();} for (File file:files) {String destfilename = File.getname (). ReplaceAll ("\\.java$", ". Jad"); File DestFile = new file (DestDir, destfilename); try (fileinputstream fis = new FileInputStream (File); FileOutputStream fos = new FileOutputStream (destfile)) {copy (Fis,fos);}} public static void Copy (InputStream IPs, OutputStream Ops) throws Ioexception{byte[] Bbuf = new Byte[1024];int Hasread = 0;while ((Hasread = Ips.read (bbuf)) > 0) {ops.write (bbuf, 0, Hasread);}}} 

Write a program to copy all the. java files under the D:\java directory to the D:\jad directory and change the original file's extension from. java to. jad.

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.