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

Source: Internet
Author: User
Import Java.io.BufferedReader; Import Java.io.BufferedWriter; Import Java.io.File; Import Java.io.FileReader; Import Java.io.FileWriter; Import Java.io.FilenameFilter; Import java.io.IOException;
public class Copyfoldertest {public static void main (string[] args) throws IOException {//Encapsulate data source and destination Fil       e file1 = new File ("D:\\java"); File File2 = new file ("D:\\jad");
File filter Encapsulation directory String array object, anonymous object string[] Strarr = file1.list (new FilenameFilter() {
@Override Public Boolean Accept(File dir, String name) {//Judge condition file and suffix return new file (dir, name). Isfile () && name. EndsWith(". Java"); }       });
Traversal for (String Str:strarr) {
An input stream that encapsulates a qualified data source BufferedReader br = new BufferedReader (new FileReader (new F) Ile (File1, str));
Output stream, renaming and encapsulating the destination to be mounted bufferedwriter bw = new BufferedWriter (new FileWriter (File2, str. Replace(". Java", ". Jad")));
        //traversal read-write file         string line = null;         while (line = Br.readline ())!= null) {                bw.write (line);                bw.newline ();                bw.flush ();           }            br.close ();           bw.close ();      }   &nbsp}}
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.