Copy all. java files in the D:/java directory to the D:/jad directory and change the extension of the original file from. java to. jad
Import Java.io.File; Import Java.io.FileInputStream; Import Java.io.FileOutputStream; Import Java.io.FilenameFilter; Import Java.io.InputStream; Import Java.io.OutputStream; /** * * Write a program to copy all the. java files in the D:/java directory to the D:/jad directory and change the extension of the original file from. java to. jad. * Aug 3/public class Jad2java {public static void main (string[] args) throws Exception {file Srcdir = new file ( "Java"); if (!) ( Srcdir.exists () && srcdir.isdirectory ()) throw new Exception ("directory does not exist"); file[] files = srcdir.listfiles (new FilenameFilter () {public Boolean accept (File dir, String name) {return Name.endswith (". Java"); } } ); System.out.println ("A total of" +files.length+ "Java Files"); File Destdir = new file ("Jad"); if (!destdir.exists ()) Destdir.mkdir (); for (File f:files) {FileInputStream FIS = new FileInputStream (f); String destfilename = F.getname (). ReplaceAll ("//.java$", ". Jad"); FileOutputStream fos = new FileOutputStream (new File (Destdir,destfilename)); Copy (Fis,fos); Fis.close (); Fos.close (); }} private static void CopY (InputStream Ips,outputstream ops) throws exception{int len = 0; byte[] buf = new byte[1024]; while (len = Ips.read (BUF) )!=-1) {ops.write (Buf,0,len);}} }