import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.ProgressMonitorInputStream;
import javax.swing.border.EmptyBorder;
public class test1 extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
private static String fileName = "sdk-tools-windows-3859397.zip";
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
test1 frame = new test1();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*
* @throws Exception
*/
@SuppressWarnings("resource")
public test1() throws Exception {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));
setContentPane(contentPane);
ProgressMonitorInputStream df = new ProgressMonitorInputStream(null, "null" + fileName,
new FileInputStream(fileName));
InputStream in = new BufferedInputStream(df);
byte[] b = new byte[1024 * 500];//接收数据的数组
int len = 0;//多少组数据
String str="";
int i=0;
while ((len = in.read(b)) != -1) {
i++;
str+=""+b[i];
System.out.println("读取了[" + len + "]个字节"+" 每组里的数据"+str);
Thread.sleep(100);
}
}
}