public class ProgressMonitorInputStream extends FilterInputStream
  InputStream in = new BufferedInputStream(
                          new ProgressMonitorInputStream(
                                  parentComponent,
                                  "Reading " + fileName,
                                  new FileInputStream(fileName)));  
       这将创建一个进度监视器来监视读取输入流的进度。 如果需要一段时间,将弹出一个ProgressDialog来通知用户。 如果用户点击“取消”按钮,则会在下次读取时抛出InterruptedIOException异常。 所有正确的清理都是在流关闭时完成的。
有关进一步的文档和示例,请参阅Java Tutorial中的 How to Monitor Progress 。
ProgressMonitor , JOptionPane 
       in| Constructor and Description | 
|---|
| ProgressMonitorInputStream(Component parentComponent, Object message, InputStream in)
              构造一个对象来监视输入流的进度。 
             | 
| Modifier and Type | Method and Description | 
|---|---|
| void | close()
              覆盖 
              FilterInputStream.close以关闭进度监视器以及流。 | 
| ProgressMonitor | getProgressMonitor()
              获取此流所使用的ProgressMonitor对象。 
             | 
| int | read()
              覆盖 
              FilterInputStream.read,以便在读取后更新进度监视器。 | 
| int | read(byte[] b)
              覆盖 
              FilterInputStream.read,以便在读取后更新进度监视器。 | 
| int | read(byte[] b, int off, int len)
              覆盖 
              FilterInputStream.read,以便在读取后更新进度监视器。 | 
| void | reset()
              覆盖 
              FilterInputStream.reset以重置进度监视器以及流。 | 
| long | skip(long n)
              覆盖 
              FilterInputStream.skip以在跳过后更新进度监视器。 | 
available, mark, markSupportedpublic ProgressMonitorInputStream(Component parentComponent, Object message, InputStream in)
message - 描述性文本放在对话框中,如果弹出。 
           parentComponent - 触发被监视操作的组件。 
           in - 要监视的输入流。 
           public ProgressMonitor getProgressMonitor()
public int read()
         throws IOException 
          FilterInputStream.read以便在读取后更新进度监视器。 
          read在 
            FilterInputStream类 
           -1 。 
           IOException - 如果发生I / O错误。 
           FilterInputStream.in 
           public int read(byte[] b)
         throws IOException 
          FilterInputStream.read以便在读取后更新进度监视器。 
          read在 
            FilterInputStream 
           b - 读取数据的缓冲区。 
           -1 。 
           IOException - 如果发生I / O错误。 
           FilterInputStream.read(byte[], int, int) 
           public int read(byte[] b,
                int off,
                int len)
         throws IOException 
          FilterInputStream.read ,以便在读取后更新进度监视器。 
          read在 
            FilterInputStream 
           b - 读取数据的缓冲区。 
           off - 目标数组 
            b的起始偏移量 
           len - 读取的最大字节数。 
           -1 。 
           IOException - 如果发生I / O错误。 
           FilterInputStream.in 
           public long skip(long n)
          throws IOException 
          FilterInputStream.skip以在跳过后更新进度监视器。 
          skip在 
            FilterInputStream 
           n - 要跳过的字节数。 
           IOException - 如果流不支持查询,或者发生其他I / O错误。 
           public void close()
           throws IOException 
          FilterInputStream.close以关闭进度监视器以及流。 
          close在接口 
            Closeable 
           close在接口 
            AutoCloseable 
           close在 
            FilterInputStream 
           IOException - 如果发生I / O错误。 
           FilterInputStream.in 
           public void reset()
           throws IOException 
          FilterInputStream.reset以重置进度监视器以及流。 
          reset在 
            FilterInputStream 
           IOException - 如果流未标记或标记已被无效。 
           FilterInputStream.in , 
            FilterInputStream.mark(int) 
            Submit a bug or feature 
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
 Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.