Java interview: 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__java

Source: Internet
Author: User

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);}} }

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.