如果 b 的长度为 0,则不读取任何字节并返回 0;否则,尝试读取至少一个字节。如果因为流位于文件末尾而没有可用的字节,则返回值 -1;否则,至少读取一个字节并将其存储在 b 中。 ======================================================================================
为什么不看API文档呢?JDK文档又有中文版。

解决方案 »

  1.   

    inputStream.read(buf) != -1;
      

  2.   

    给你个例子import java.io.*;
    public class TestFileInputStream {
      public static void main(String[] args) {
        int b = 0;
        FileInputStream in = null;
        try {
          in = new FileInputStream("d:\\share\\java\\io\\TestFileInputStream.java");
        } catch (FileNotFoundException e) {
          System.out.println("找不到指定文件"); 
          System.exit(-1);
        }
        
        try {
          long num = 0;
          while((b=in.read())!=-1){
            System.out.print((char)b); 
            num++;
          }
          in.close();  
          System.out.println();
          System.out.println("共读取了 "+num+" 个字节");
        } catch (IOException e1) {
          System.out.println("文件读取错误"); System.exit(-1);
        }
      }
    }
      

  3.   

    看LS的例子
    while((b=in.read())!=-1)