import java.io.*;
class TestIO_available{
public static void main(String args[]) {
InputStream s = null;
try{
s = new FileInputStream("io2.txt");
}catch(FileNotFoundException e){
System.out.println("file not find");
e.printStackTrace();
}
System.out.println("file success found!");
int i,rest;
try{
i = s.read();
rest=s.available();
while((rest != 0) ||(i != -1)){
if(rest == 0)
System.out.println("\nrest == 0");
System.out.print((char)i);
i = s.read();
rest=s.available();
}
}catch(IOException e){
//System.out.println("io error");
e.printStackTrace();
}
}
}
/*
123 456
asd
fg
rest == 0
请按任意键继续. . .
*/
/*
file not find
java.io.FileNotFoundException: io2.txt (系统找不到指定的文件。)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at TestIO_available.main(TestIO_available.java:12)
file success found!
Exception in thread "main" java.lang.NullPointerException
at TestIO_available.main(TestIO_available.java:27)
请按任意键继续. . .
*/
TestIO_available
最新推荐文章于 2022-07-26 17:06:55 发布