com.google.cloud.storage.Blob.downloadTo()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(3.1k)|赞(0)|评价(0)|浏览(147)

本文整理了Java中com.google.cloud.storage.Blob.downloadTo()方法的一些代码示例,展示了Blob.downloadTo()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Blob.downloadTo()方法的具体详情如下:
包路径:com.google.cloud.storage.Blob
类名称:Blob
方法名:downloadTo

Blob.downloadTo介绍

[英]Downloads this blob to the given file path.

This method is replaced with #downloadTo(Path,BlobSourceOption...), but is kept here for binary compatibility with the older versions of the client library.
[中]将此blob下载到给定的文件路径。
此方法替换为#downloadTo(路径、BlobSourceOption…),但保留在这里是为了与旧版本的客户端库保持二进制兼容性。

代码示例

代码示例来源:origin: googleapis/google-cloud-java

/**
 * 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]);
}

代码示例来源:origin: googleapis/google-cloud-java

/** 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]
}

代码示例来源:origin: googleapis/google-cloud-java

/** 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]
}

代码示例来源:origin: googleapis/google-cloud-java

blob.downloadTo(file.toPath());
byte actual[] = Files.readAllBytes(file.toPath());
assertArrayEquals(expected, actual);

代码示例来源:origin: com.google.cloud/google-cloud-storage

/**
 * 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]);
}

相关文章