public void testGetObject() { try { S3Object o = s3.getObject(BUCKET_NAME, KEY); System.out.println(o); S3ObjectInputStream s3is = o.getObjectContent(); File directory = new File(""); // 参数为空 FileOutputStream fos = new FileOutputStream(new File(directory.getCanonicalPath() + "/MYTEST")); byte[] read_buf = new byte[1024]; int read_len = 0; while ((read_len = s3is.read(read_buf)) > 0) { fos.write(read_buf, 0, read_len); } s3is.close(); fos.close(); } catch (AmazonServiceException e) { System.err.print("Get object faild, err :" + e); } catch (FileNotFoundException e) { System.err.println(e.getMessage()); System.exit(1); } catch (IOException e) { System.err.println(e.getMessage()); System.exit(1); } } |