急 求: 用 java 编写一个小程序

2024-11-22 14:45:30
推荐回答(2个)
回答(1):

//我替你写了一个DEMO,执行的前提条件是,先在D盘把目录创建好
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

public class T {

public static void main(String[] args) throws Exception{
String path = "d:\\java";
File file = new File(path);

int count = 0;

for(File item:file.listFiles()){
if(item.toString().endsWith(".java")){

FileInputStream fis = new FileInputStream(item);

File fileout = new File("d:\\jad\\"+getPath(item.toString()));
FileOutputStream fos = new FileOutputStream(fileout);

byte []buff = new byte[1024];
int read = -1;

while((read = fis.read(buff))!=-1){
fos.write(buff, 0, read);
}

fis.close();
fos.close();
System.out.println("文件"+item.toString()+"被成功复制!");
count++;
}
}
System.out.println("所有文件复制完成,共复制了"+count+"个文件!");
}

private static String getPath(String local){
return local.substring(local.lastIndexOf("\\")+1, local.length()).replace(".java", ".jad");
}

}

回答(2):

改名就可以了