If you want to see the reading progress of the file when reading the file, you can use the input stream class ProgressMonitorInputStream provided by the javax.swing package. Its construction method is:
ProgressMonitorInputStream(Conmponentc,Strings,InputStream);
When the input stream created by this class reads a file, a progress bar will pop up showing the reading speed. The progress bar will be displayed directly in front of the component specified by parameter c. If this parameter is null, it will be displayed directly in front of the screen.
For example, to read the contents of a file using an input stream with a progress bar:
importjavax.swing.*;importjava.io.*;publicclassMain{publicstaticvoidmain(Stringargs[]){byteb[]=newbyte[30];try{FileInputStreaminput=newFileInputStream(Main.java);ProgressMonitorInputStreamin=newProgressMonitorInputStream(null, read java File, input);ProgressMonitorp=in.getProgressMonitor();//Get the progress bar while(in.read(b)!=-1){Strings=newString(b);System.out.print(s);Thread. sleep(1000);//Because the file is small, in order to see the progress bar clearly, the delay is intentionally delayed by 1000 milliseconds}}catch(Exceptione){}}}