我正在尝试从 Google Cloud Storage 下载文件。我在第 1042 行使用 Google 的 Github 代码。我相信我的错误在于文件路径。路径变量用于说明文件下载到的位置及其新名称,对吗?请注意,我正在使用 JSP 按钮来启动该过程。为了让我自己更容易解决,我用字符串而不是 HttpServletRequest 替换了字符串和路径变量。
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// [START storage_download_file]
// The name of the bucket to access
String bucketName = "media";
// The name of the remote file to download
String srcFilename = "File.rtf";
// The path to which the file should be downloaded
Path destFilePath = Paths.get("/Volumes/Macintosh HD/Users/ab/Desktop/File.rtf");
// 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]
}
引起:java.nio.file.NoSuchFileException:/Volumes/Macintosh HD/Users/ab/Desktop/File.rtf