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