4
Java 서블릿을 사용하여 파일을 다운로드하기위한 Java Swing 응용 프로그램을 만들었습니다.Java Swing 응용 프로그램의 진행 표시 줄
클라이언트 시스템에는 다운로드 할 파일 목록을 제공하는 GUI가 있습니다.
파일 다운로드를 모니터링하는 진행률 막대를 어떻게 설정합니까?
b2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
HttpClient client = new DefaultHttpClient();
String value = comboBox1.getSelectedItem().toString();
HttpGet post = new HttpGet(
"http://localhost:8080/may16/FileDownloadServletNormal?value="
+ value + "&type=normal");
try {
LocalTime time1 = new LocalTime();
// executing the POST request
HttpResponse rsp = client.execute(post);
// reading response data
HttpEntity entity = rsp.getEntity();
InputStream inputStream = entity.getContent();
OutputStream outputStream = new FileOutputStream(
new File("D://temp//downloaded//" + value));
IOUtils.copy(inputStream, outputStream);
/*try {
Thread.sleep(25000);
}
catch (InterruptedException e) {
//TODO Auto-generated catch block
e.printStackTrace();
}*/
outputStream.flush();
outputStream.close();
LocalTime time2 = new LocalTime();
Seconds sec = Seconds.secondsBetween(time1, time2);
System.out.println("Time Taken:" + sec.getSeconds() + "secs");
//normalDownloadTime.setText("Normal download time:"+sec.getSeconds());
normalDownloadTime.setText("Normal download time:"
+ sec.getSeconds() + "secs");
// String response = convertStreamToString(inputStream);
// System.out.println(response);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
});