Progress monitor -- ProgressMonitorInputStream,
Progress monitor -- ProgressMonitorInputStream
ProgressMonitorInputStream
You can create a progress monitor to monitor the progress of reading input streams. If it takes a while, ProgressDialog will pop up to notify the user. If you click the Cancel button, InterruptedIOException is thrown during the next read operation. When the stream is disabled, all the correct cleanup operations are performed.
The progress bar is as follows:
The Code is as follows:
1 import java. io. *; 2 3 import javax. swing. *; 4 5 public class Fuck {6 public static void main (String [] temp) {7 byte B [] = new byte [2]; 8 try {9 FileInputStream FCM = new FileInputStream ("d :\\ user. xml "); 10 ProgressMonitorInputStream in = 11 new ProgressMonitorInputStream (null," Read File ", FS); 12 while (in. read (B )! =-1) {13 String s = new String (B); 14 System. out. print (s); 15 Thread. sleep (100); 16} 17} catch (Exception e) {18 e. printStackTrace (); 19} 20} 21}
ProgressMonitorInputStream has three attributes:
Component parentComponent determines which Component the progress bar is attached
Content displayed on the object message progress bar
InputStream in byte input stream (file to be read)