2023-04-20 08:42:48hammonddsy

JAVA 若何在LINUX COPY files時泛起PRO

有利用過進度條的朋友必然會覺得很不輕易
因為要從0~100讀取 華侈時間
因檔案巨細也不知道這時候間讀寫的完嗎?
如這篇
Java Swing 若何利用進度

於是顛末修正
改成此方法
可利用DIALOG準確的抓到讀寫完成的時候

  1. processdialog.setTitle("Copying files to USB");
  2.                             processdialog.add(labelimg);
  3.                             processdialog.setLocation(400,250);
  4.                             processdialog.pack(); // Packs the dialog so that the JOptionPane can be seen
  5.                             processdialog.setVisible(true); // Shows the dialog
  6.                             new Thread(){
  7.                                     public void run(){
  8.                                             try{
  9.                                                 Process process = null;
  10.                                                 BufferedReader input = null;
  11.                                                 final Runtime runtime = Runtime.getRuntime();
  12.                                                 //extact tar for ext3 file
  13.                                                 String tarstring = "tar -xvpf /"+tarpath+"/"+cellValue+".tar -C "+extpatition+"/";
  14.                                                 process = runtime.exec(new String[]{"/bin/sh","-c",tarstring});
  15.                                                 InputStream stdout = process.getInputStream ();
  16.                                                 InputStreamReader osr = new InputStreamReader (stdout);
  17.                                                 BufferedReader obr = new BufferedReader (osr);
  18.                                                 process.waitFor();
  19.                                                
  20.                                                 Thread.sleep(2000);
  21.                                             }catch(Exception e){
  22.                                                     e.printStackTrace();
  23.                                             }finally{
  24.                                                     processdialog.dispose();
  25.                                             }
  26.                                     }
  27.                             }.start();
複製代碼

網站架設new Thread如許包起來就能夠了網站架設
問甚麼要如許做呢?
因為dialog其實是很是鋪張資本的
如果我程式肇端啟動dialog
竣事用dialog網站架設.dispose();時
dialog圖標根本還沒出來就關閉了
就卡個視窗而以
完整過程圖片

1.png

網站架設

以下文章來自: