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項目下存放著
感謝大神解答~~~
展開