import java.io.*;
public class readFile{
public static void main(String args[]){
int a;
FileInputStream fis;
try{
fis=new FileInputStream(args[0]);//为什么要args[0]这个参数?
}catch(FileNotFoundException e){
System.out.println("File not found!");
return; //什么作用呀?
}catch(ArrayIndexOutOfBoundsException e){//是只要出现数组就要写数组出界异常吗?
System.out.println("Usage:readFile FileName");
return;
}
try{
do{
a=fis.read();
if(a!=-1)System.out.println((char)a);//a!=-1什么含义是输入enter键的意思吗?
}while(a!=-1);
fis.close();//不关闭文件会有什么影响呢?
}catch(IOException e){
System.out.println("IO异常");
}
}
}
public class readFile{
public static void main(String args[]){
int a;
FileInputStream fis;
try{
fis=new FileInputStream(args[0]);//为什么要args[0]这个参数?
}catch(FileNotFoundException e){
System.out.println("File not found!");
return; //什么作用呀?
}catch(ArrayIndexOutOfBoundsException e){//是只要出现数组就要写数组出界异常吗?
System.out.println("Usage:readFile FileName");
return;
}
try{
do{
a=fis.read();
if(a!=-1)System.out.println((char)a);//a!=-1什么含义是输入enter键的意思吗?
}while(a!=-1);
fis.close();//不关闭文件会有什么影响呢?
}catch(IOException e){
System.out.println("IO异常");
}
}
}
public class readFile{
public static void main(String args[]){
int a;
FileInputStream fis;
try{
fis=new FileInputStream(args[0]);//为什么要args[0]这个参数?A:args[0]是运行程序是船进的参数
}catch(FileNotFoundException e){
System.out.println("File not found!");
return; //什么作用呀?A:捕捉到该异常就返回,不再进行下面的异常捕捉。
}catch(ArrayIndexOutOfBoundsException e){//是只要出现数组就要写数组出界异常吗?A:应该是。但似乎这个错误系统会捕捉,不用写出来。
System.out.println("Usage:readFile FileName");
return;
}
try{
do{
a=fis.read();
if(a!=-1)System.out.println((char)a);//a!=-1什么含义是输入enter键的意思吗?A:a相当于fis不断读出的字符,如果为-1,大概就是文件结束。
}while(a!=-1);
fis.close();//不关闭文件会有什么影响呢?A:如果不关闭,在其他地方要再打开这个文件会出问题。
}catch(IOException e){
System.out.println("IO异常");
}
}
}