import java.io.*;
public class IOTest{
public static void main(String[] args){
int b=0;
try{
FileInputStream fis=new FileInputStream("IOTest.java"); //和下面标记代码不一样的地方.
}
catch(FileNotFoundException e){
System.out.println("the file doesn't exist.");
}
try{
while((b=fis.read())!=-1){
System.out.print((char)b);
}
fis.close();
}catch(IOException e){
System.out.println("IOException");
}
}
} //这个代码编译会通不过,其实和下面这两个代码就
//一点不一样,为什么呢??
public class TestFileInputStream{
public static void main(String[] args){
int b=0;
FileInputStream fis=null; //标记位置.
try{
fis=new FileInputStream("IOTest.java");
}
catch(FileNotFoundException e){
System.out.println("the file doesn't exist.");
}
try{
while((b=fis.read())!=-1){
System.out.print((char)b);
}
fis.close();
}catch(IOException e){
System.out.println("IOException");
}
}
}
public class IOTest{
public static void main(String[] args){
int b=0;
try{
FileInputStream fis=new FileInputStream("IOTest.java"); //和下面标记代码不一样的地方.
}
catch(FileNotFoundException e){
System.out.println("the file doesn't exist.");
}
try{
while((b=fis.read())!=-1){
System.out.print((char)b);
}
fis.close();
}catch(IOException e){
System.out.println("IOException");
}
}
} //这个代码编译会通不过,其实和下面这两个代码就
//一点不一样,为什么呢??
public class TestFileInputStream{
public static void main(String[] args){
int b=0;
FileInputStream fis=null; //标记位置.
try{
fis=new FileInputStream("IOTest.java");
}
catch(FileNotFoundException e){
System.out.println("the file doesn't exist.");
}
try{
while((b=fis.read())!=-1){
System.out.print((char)b);
}
fis.close();
}catch(IOException e){
System.out.println("IOException");
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货