Copy all java files in a path to another folder and rename it as a jad file.

Source: Internet
Author: User

Copy all java files in a path to another folder and rename it as a jad file.

The requirement is very simple, and the program is not difficult. After seeing the question, I did not use eclipse for the first time. Instead, I used an editor to compile a program, which was simple but implemented functions.

The Code is as follows:

 

import java.io.*;class Copy{public void copy(String srcPath, String targetPath) throws Exception{File srcFolder = new File(srcPath);File tarFolder = new File(targetPath);if(!tarFolder.exists()){tarFolder.mkdirs();}FileFilter filter = new FileFilter(){public boolean accept(File file){if(file.getName().endsWith(.java)){return true;}return false;}};File[] srcFiles = srcFolder.listFiles(filter);InputStream ins = null;OutputStream ots = null;for(File srcFile:srcFiles){if(srcFile.exists()){String fileName = srcFile.getName();ins = new FileInputStream(srcFile);ots = new FileOutputStream(targetPath+/+fileName.replace(java,jad));int reader = -1;byte[] readByte = new byte[1024];while((reader=ins.read(readByte))!=-1){ots.write(readByte,0,reader);}}}if(ots!=null){ots.close();}if(ins!=null){ins.close();}}public static void main(String[] args){Copy obj = new Copy();try{obj.copy(D:/test/test1,D:/test/test2);}catch(Exception e){e.printStackTrace();}}}

 

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.