我编写的程序在java中获取文件信息并在GUI中显示信息。当我使用NetBeans运行程序时,它可以正常工作,但是当我构建它的jar文件时,我面临连接超时错误。这是代码:
private void btnFileAddressActionPerformed(java.awt.event.ActionEvent evt) {
btnSendForDownload.setEnabled(false);
if(txtFileAddress.getText().equalsIgnoreCase("")){
JOptionPane.showMessageDialog(null, "آدرس فایل را وارد نمایید", "هشدار", JOptionPane.INFORMATION_MESSAGE, null);
return;
}
try {
fileAddress = new URL(txtFileAddress.getText());
connection = (HttpURLConnection) fileAddress.openConnection();
connection.setRequestMethod("GET");
connection.setConnectTimeout(30 * 1000);
fileSize = ((float)(connection.getContentLength()));
if(fileSize <= 1024){
lblVolumeValue.setText(fileSize + " بایت");
}
else if(1024 < fileSize && fileSize <= 1024 * 1024){
lblVolumeValue.setText(String.format("%.2f کیلوبایت", (fileSize / 1024)));
}
else if(1024 * 1024 < fileSize && fileSize <= 1024 * 1024 * 1024){
lblVolumeValue.setText(String.format("%.2f مگابایت", (fileSize / (1024 * 1024))));
}
else{
lblVolumeValue.setText(String.format("%.2f گیگابایت", (fileSize / (1024 * 1024 * 1024))));
}
lblStatueValue.setText(String.valueOf(connection.getResponseCode()));
lblFileExtensionValue.setText(txtFileAddress.getText().substring(txtFileAddress.getText().lastIndexOf(".") + 1, txtFileAddress.getText().length()));
lblPortionSizeValue.setText(String.valueOf((int)fileSize / downloadersCount) + " B");
lblRemainValue.setText((String.valueOf(((int)(fileSize)) % downloadersCount)) + " B");
lblFileNameValue.setText(txtFileAddress.getText().substring(txtFileAddress.getText().lastIndexOf("/") + 1 , txtFileAddress.getText().lastIndexOf(".")));
} catch (MalformedURLException ex) {
JOptionPane.showMessageDialog(null, ex.getMessage(), "هشدار", JOptionPane.INFORMATION_MESSAGE, null);
} catch (IOException ex) {
JOptionPane.showMessageDialog(null, ex.getMessage(), "هشدار", JOptionPane.INFORMATION_MESSAGE, null);
}
}
我的连接有什么问题?为什么在构建的jar文件中超时?
修改
这是构建运行jar的image链接
这是运行IDE
的image链接