/** * Downloads this blob to the given file path. * * <p>This method is replaced with {@link #downloadTo(Path, BlobSourceOption...)}, but is kept * here for binary compatibility with the older versions of the client library. * * @param path destination * @throws StorageException upon failure */ public void downloadTo(Path path) { downloadTo(path, new BlobSourceOption[0]); }
/** Example of downloading a file. */ public void downloadFile(String bucketName, String srcFilename, Path destFilePath) throws IOException { // [START storage_download_file] // The name of the bucket to access // String bucketName = "my-bucket"; // The name of the remote file to download // String srcFilename = "file.txt"; // The path to which the file should be downloaded // Path destFilePath = Paths.get("/local/path/to/file.txt"); // Instantiate a Google Cloud Storage client Storage storage = StorageOptions.getDefaultInstance().getService(); // Get specific file from specified bucket Blob blob = storage.get(BlobId.of(bucketName, srcFilename)); // Download file to specified path blob.downloadTo(destFilePath); // [END storage_download_file] }
/** Example of downloading a file using Requester pay. */ public void downloadFileUsingRequesterPays( String projectId, String bucketName, String srcFilename, Path destFilePath) throws IOException { // [START storage_download_file_requester_pays] // The project ID to bill // String projectId = "my-billable-project-id"; // The name of the bucket to access // String bucketName = "my-bucket"; // The name of the remote file to download // String srcFilename = "file.txt"; // The path to which the file should be downloaded // Path destFilePath = Paths.get("/local/path/to/file.txt"); // Instantiate a Google Cloud Storage client Storage storage = StorageOptions.getDefaultInstance().getService(); // Get specific file from specified bucket Blob blob = storage.get(BlobId.of(bucketName, srcFilename)); // Download file to specified path blob.downloadTo(destFilePath, Blob.BlobSourceOption.userProject(projectId)); // [END storage_download_file_requester_pays] }
blob.downloadTo(file.toPath()); byte actual[] = Files.readAllBytes(file.toPath()); assertArrayEquals(expected, actual);
/** * Downloads this blob to the given file path. * * <p>This method is replaced with {@link #downloadTo(Path, BlobSourceOption...)}, but is kept * here for binary compatibility with the older versions of the client library. * * @param path destination * @throws StorageException upon failure */ public void downloadTo(Path path) { downloadTo(path, new BlobSourceOption[0]); }