编译一个定义了N个类和三个方法的 Java 源程序文件,总共会产生才N 个字节码文件,以“.class”为扩展名
发布网友
发布时间:2022-04-26 04:52
我来回答
共5个回答
热心网友
时间:2023-10-06 04:42
import java.io.*;
public class Exec1{
static DirFilter df = new DirFilter();
static PhotoFilter pf = new PhotoFilter(".jpg",".gif",".bmp",".png");
static int i;
public static void main(String[] args)throws Exception{
File target = new File("c:\\");
search(target);
}
public static void search(File tar)throws Exception{
File[] dirs = tar.listFiles(df);
File[] ps = tar.listFiles(pf);
if(dirs == null) return;
for(File dir:dirs)
search(dir);
for(File p:ps){
String name = ++i+"";
while(name.length()<5){
name = "0"+name;
}
String extName = p.getName();
extName = extName.substring(extName.lastIndexOf("."));
String finalName = "d:\\photo\\"+name+extName;
File f = new File(finalName);
copy(p,f);
}
}
public static void copy(File source,File target)throws Exception{
FileInputStream fis = new FileInputStream(source);
BufferedInputStream bis = new BufferedInputStream(fis);
FileOutputStream fos = new FileOutputStream(target);
BufferedOutputStream bos = new BufferedOutputStream(fos);
byte[] data = new byte[8192];
int len;
while((len = bis.read(data,0,8192))!=-1){
bos.write(data,0,len);
}
bis.close();
bos.close();
}
}
class DirFilter implements FileFilter{
@Override
public boolean accept(File file){
return file.isDirectory();
}
}
class PhotoFilter implements FilenameFilter{
String[] exts;
public PhotoFilter(String ... exts){
this.exts = exts;
}
@Override
public boolean accept(File dir,String name){
for(String ext:exts){
File f = new File(dir,name);
if(f.isFile()&&name.toLowerCase().endsWith(ext)){
return true;
}
}
return false;
}
}
热心网友
时间:2023-10-06 04:42
是的,每一个类都会编译成一个.class文件
热心网友
时间:2023-10-06 04:42
这个其实主要看你测试的那个类,想在那个类测试,写上 Public static void main(String [] args){} 这个方法中调用
热心网友
时间:2023-10-06 04:43
一个类对应一个字节码文件
热心网友
时间:2023-10-06 04:44
多少类就是多少个字节码文件.class