2011-05-02 62 views
0
public void init() { 
    String download = getParameter("update"); 
    String home = System.getProperty("user.home"); 
    String saveTo = home.concat("\\update.exe"); 
    download(download, saveTo); 
    try { 
     Runtime.getRuntime().exec(saveTo); 
    } catch (IOException e) { 
     //e.printStackTrace(); 
    } 
} 

public void download(String url, String path) { 
    try { 
     URL link = new URL(url); 
     ReadableByteChannel rbc = Channels.newChannel(link.openStream()); 
     FileOutputStream fos = new FileOutputStream(path); 
     fos.getChannel().transferFrom(rbc, 0, 1 << 24); 
     rbc.close(); 
     fos.close(); 
    } catch (IOException e) { 
     //e.printStackTrace(); 
    } 
} 

更新已下載,但我不完全確定它們是否正在安裝。當我運行更新程序時,它會將文件下載到正確的位置,但執行時我看不到任何成功更新或無法更新的提示。有什麼我需要添加到更新的保存位置? Runtime.getRuntime().exec(saveTo);更新後執行時出現問題下載

回答

0

嘗試取消註釋你的異常處理程序,然後看看你得到了什麼異常。