初级的I/O使用.
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
public class IOWrite{
@SuppressWarnings("finally")
public static void main(String[] args) throws IOException {
int i ;
FileInputStream fin = null ;
try{
fin = new FileInputStream(args[0]);
}catch(FileNotFoundException e){
System.out.println("File Not Foud " + e);
}
try {
do {
i=fin.read();
if(i != -1)System.out.print((char)i);
} while (i != -1);
} catch (IOException e) {
System.out.println("I/O Error");
}
try{
fin.close();
}catch(IOException e){
System.out.println("Closeing file Failed");
}finally{
fin.close();
return ;
}
}
}
今天学习了如何使用Java的FileInputStream()进行文件读取.