- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.FilenameFilter;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.OutputStream;
-
- public class Jad2Java {
-
- public static voidmain(String[] args) throws Exception {
- File srcDir =new File("java"); if(!(srcDir.exists()&& srcDir.isDirectory()))
- thrownew Exception("目录不存在");
- File[] files= srcDir.listFiles(
- newFilenameFilter(){
-
- publicboolean accept(File dir, String name) {
- returnname.endsWith(".java");
- }
-
- }
- );
-
- System.out.println(files.length);
- File destDir= new File("jad");
- if(!destDir.exists())destDir.mkdir();
- for(File f:files){
- FileInputStream fis = new FileInputStream(f);
- StringdestFileName = f.getName().replaceAll("\\.java$", ".jad");
- FileOutputStreamfos = 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);
- }
- }
复制代码
|