ProgressMonitorInputStream Demo : Data Input Output « File Input Output « Java






ProgressMonitorInputStream Demo

 
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 ProgressInputSample {
  public static final int NORMAL = 0;

  public static void main(String args[]) throws Exception {
    int returnValue = NORMAL;
    if (args.length != 1) {
      System.err.println("Usage:");
      System.err.println("java ProgressInput filename");
    } else {
      FileInputStream fis = new FileInputStream(args[0]);
      JLabel filenameLabel = new JLabel(args[0], 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);
        Thread.sleep(500);
      }
      br.close();
    }
    // AWT Thread created - must exit
    System.exit(returnValue);
  }
}

           
         
  








Related examples in the same category

1.The use of DataOutputStream and DataInputStream:
2.Data IO Test 2Data IO Test 2
3.Data IO DemoData IO Demo
4.Data IO Test Data IO Test
5.Typical I/O stream configurations
6.IO demo: DataOutputStream and DataInputStream
7.Some simple file I-O primitives reimplemented in Java
8.ScanStreamTok - show scanning a file with StringTokenizer
9.Write some data in binary
10.Using transferTo() between channels
11.Controlling serialization by adding your own writeObject() and readObject() methodsControlling serialization by adding your own writeObject() and readObject() methods
12.Read Write Lock TestRead Write Lock Test
13.Bit InputStream