importjava.io.*;importjavax.swing.*;publicclassIOMonitor{publicstaticvoidmain(String[]temp){//TODO自动生成的方法存根byteb[]=newbyte[2];try{FileInputStreamfis=newFileInput...
import java.io.*;
import javax.swing.*;
public class IOMonitor {
public static void main(String[] temp) {
// TODO 自动生成的方法存根
byte b[] = new byte[2];
try{
FileInputStream fis = new FileInputStream("word.txt");
ProgressMonitorInputStream in =
new ProgressMonitorInputStream(null,"读取文件",fis);
while(in.read(b)!=-1){
String s = new String(b);
System.out.print(s);
Thread.sleep(10);
}
in.close();
}catch (Exception e) {
e.printStackTrace();
}
}
}
这段代码中字节数组b有什么作用?为什么System.out.print(s);会把word.txt中的内容完全显示出来,s是怎么和word.txt的内容建立关系的?对于while循环中的代码特别理解不了:
while(in.read(b)!=-1){
String s = new String(b);
System.out.print(s);
Thread.sleep(10);
}
说明一下:word.txt 是已经存在的一个文档,就在IOMinitor项目下存放着
感谢大神解答~~~
展开