我正在使用以下代碼使用PUT請求將文件上載到服務器。這工作正常。但我想添加一個JProgressBar
這個代碼,你如何建議我這樣做?我不確定要使用哪些類來實現我需要的進度條。需要將JProgressBar添加到swing應用程序的幫助
RequestEntity re = new RequestEntity() {
@Override
public long getContentLength() {
// TODO Auto-generated method stub
return file.length();
}
@Override
public String getContentType() {
// TODO Auto-generated method stub
return "application/octet-stream";
}
@Override
public boolean isRepeatable() {
// TODO Auto-generated method stub
return true;
}
@Override
public void writeRequest(OutputStream outputStream) throws IOException {
// TODO Auto-generated method stub
InputStream in = new FileInputStream(file);
try {
int l;
byte[] buffer = new byte[1024];
while ((l = in.read(buffer)) != -1) {
outputStream.write(buffer, 0, l);
}
} finally {
in.close();
}
}
};
你還沒有顯示任何GUI代碼,你有嗎?或者你期望別人寫它? – roippi
看看[這](http://stackoverflow.com/questions/12185924/show-progress-during-ftp-file-upload-in-a-java-applet/12186144#12186144)和[這裏]( http://stackoverflow.com/questions/16272842/multithreading-in-java-i-want-both-ui-and-code-to-execute-in-parallel/16272933#16272933)爲例子 – MadProgrammer
我對索裏roippi那個,但是代碼太多了,這就是我沒有放棄的原因。 – user1386101