package august_21;
import java.io.*;
public class ReadBytes {
public static void main(String[] args) {
try{
FileInputStream file=new FileInputStream("ReadBytes.clas");
boolean eof=false;
int count=0;
while(!eof){
int input=file.read();
System.out.print(input+" ");
if(input==-1){
eof=true;
}
else{
count++;
}
}
file.close();
System.out.println("\nByte read:"+count);
}
catch(IOException e){
System.out.println("Error--"+e.toString());
}
}
}
题目说是 以字节方式读取源程序对应的类文件,并显示出来
然而我在Eclipse上写完,运行了会抛出异常,我又在控制台下生成了Class文件在运行还是不行。
这是怎么回事?求教大家下
import java.io.*;
public class ReadBytes {
public static void main(String[] args) {
try{
FileInputStream file=new FileInputStream("ReadBytes.clas");
boolean eof=false;
int count=0;
while(!eof){
int input=file.read();
System.out.print(input+" ");
if(input==-1){
eof=true;
}
else{
count++;
}
}
file.close();
System.out.println("\nByte read:"+count);
}
catch(IOException e){
System.out.println("Error--"+e.toString());
}
}
}
题目说是 以字节方式读取源程序对应的类文件,并显示出来
然而我在Eclipse上写完,运行了会抛出异常,我又在控制台下生成了Class文件在运行还是不行。
这是怎么回事?求教大家下