// 构造下载文件请求。 // 依次填写Bucket名称(例如examplebucket)和Object完整路径(例如exampledir/exampleobject.txt)。Object完整路径中不能包含Bucket名称。 GetObjectRequest get = new GetObjectRequest("examplebucket", "exporter1.xls"); oss.asyncGetObject(get, new OSSCompletedCallback<GetObjectRequest, GetObjectResult>() { @Override public void onSuccess(GetObjectRequest request, GetObjectResult result) { // 开始读取数据。 long length = result.getContentLength(); if (length > 0) { byte[] buffer = new byte[(int) length]; int readCount = 0; while (readCount < length) { try{ readCount += result.getObjectContent().read(buffer, readCount, (int) length - readCount); }catch (Exception e){ OSSLog.logInfo(e.toString()); } } // 将下载后的文件存放在指定的本地路径,例如D:\\localpath\\exampleobject.jpg。 try { FileOutputStream fout = new FileOutputStream("download_filePath"); fout.write(buffer); fout.close(); } catch (Exception e) { OSSLog.logInfo(e.toString()); } } } @Override public void onFailure(GetObjectRequest request, ClientException clientException, ServiceException serviceException) { } });