Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For <a href="http://docs.oracle.com/javase/6/docs/api/javax/swing/ProgressMonitorInputStream.html" rel="nofollow noreferrer"><code>ProgressMonitorInputStream</code></a> to work , You need to read very big file. It is specified in its document that:</p> <blockquote> <p>This creates a progress monitor to monitor the progress of reading the input stream. <strong>If it's taking a while, a ProgressDialog will be popped up to inform the user.</strong> If the user hits the Cancel button an InterruptedIOException will be thrown on the next read. All the right cleanup is done when the stream is closed.</p> </blockquote> <p>Here is the example. Make sure that you input a file(<code>bigFile.txt</code>) contains lot of stuffs to read.<br></p> <p><img src="https://i.stack.imgur.com/WkM06.jpg" alt="enter image description here"></p> <pre><code>import java.awt.Color; import java.io.BufferedReader; import java.io.FileInputStream; import java.io.InputStreamReader; import javax.swing.JLabel; import javax.swing.ProgressMonitorInputStream; public class ProgressMonitorInputStreamDemo { public static void main(String args[]) throws Exception { String file = "bigFile.txt"; FileInputStream fis = new FileInputStream(file); JLabel filenameLabel = new JLabel(file, JLabel.RIGHT); filenameLabel.setForeground(Color.black); Object message[] = { "Reading:", filenameLabel }; ProgressMonitorInputStream pmis = new ProgressMonitorInputStream(null, message, fis); InputStreamReader isr = new InputStreamReader(pmis); BufferedReader br = new BufferedReader(isr); String line; while ((line = br.readLine()) != null) { System.out.println(line); } br.close(); } } </code></pre> <p><strong>Note:</strong> <em>If you want to see <code>ProgressBar</code> , no matter how small file you are reading , You can use <a href="http://docs.oracle.com/javase/6/docs/api/javax/swing/SwingWorker.html" rel="nofollow noreferrer"><code>SwingWorker</code></a> . Have a look at</em> <strong><a href="https://stackoverflow.com/a/15710912/1981279">this Post</a></strong>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload