标签:style io ar os sp java 文件 on art
思路是:第一获取要下载文件的大小,设为X,第二通过多线程监测已下载文件的大小,设为Y,Y/x就是下载的进度。关键代码如下
//获取要下载的object的metadata ObjectMetadata tmpMetadata = client.getObjectMetadata(bucketName, key); final long filesize = tmpMetadata.getContentLength(); final File downloadFile = new File(filename); Thread t = new Thread(new Runnable() { @Override public void run() { while(true){ try { Thread.sleep(100); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println(downloadFile.getName()+"下载的进度为:"+ (float)downloadFile.length()*100/filesize); if(downloadFile.length()==filesize) break; } } }); t.start(); //下载object ObjectMetadata result =client.getObject(new GetObjectRequest(bucketName, key),downloadFile);
标签:style io ar os sp java 文件 on art
原文地址:http://blog.csdn.net/tszxlzc/article/details/41118461