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.