我正在使用以下代码使用 PUT 请求将文件上传到服务器。这工作正常。但我想在JProgressBar
这段代码中添加一个,你建议我怎么做?我不确定使用哪些类来实现我需要的进度条。
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();
}
}
};