azure java je22_使用 Java 针对 Azure 文件进行开发

使用 Java 针对 Azure 文件进行开发Develop for Azure Files with Java

12/14/2020

本文内容

了解开发使用 Azure 文件存储来存储数据的 Java 应用程序的基础知识。Learn the basics developing Java applications that use Azure Files to store data. 使用 Azure 文件存储 API 创建控制台应用程序并了解基本操作:Create a console application and learn basic actions using Azure Files APIs:

创建和删除 Azure 文件共享Create and delete Azure file shares

创建和删除目录Create and delete directories

枚举 Azure 文件共享中的文件和目录Enumerate files and directories in an Azure file share

上传、下载和删除文件Upload, download, and delete a file

提示

查看 Azure 存储代码示例存储库Check out the Azure Storage code samples repository

如需易用且能够下载和运行的端到端 Azure 存储代码示例,请查看我们的 Azure 存储示例列表。For easy-to-use end-to-end Azure Storage code samples that you can download and run, please check out our list of Azure Storage Samples.

创建 Java 应用程序Create a Java application

若要生成示例,需要 Java 开发工具包 (JDK) 和适用于 Java 的 Azure 存储 SDK。To build the samples, you'll need the Java Development Kit (JDK) and the Azure Storage SDK for Java. 此外,应该已经创建了一个 Azure 存储帐户。You should also have created an Azure storage account.

设置应用程序以使用 Azure 文件Set up your application to use Azure Files

若要使用 Azure 文件存储 API,请将以下代码添加到要通过其访问 Azure 文件存储的 Java 文件的顶部。To use the Azure Files APIs, add the following code to the top of the Java file from where you intend to access Azure Files.

// Include the following imports to use Azure Files APIs

import com.azure.storage.file.share.*;

// Include the following imports to use Azure Files APIs v11

import com.microsoft.azure.storage.*;

import com.microsoft.azure.storage.file.*;

设置 Azure 存储连接字符串Set up an Azure storage connection string

要使用 Azure 文件,需要连接到 Azure 存储帐户。To use Azure Files, you need to connect to your Azure storage account. 配置连接字符串并使用它连接到存储帐户。Configure a connection string and use it to connect to your storage account. 定义用于保存连接字符串的静态变量。Define a static variable to hold the connection string.

将 和 替换为存储帐户的实际值。Replace and with the actual values for your storage account.

// Define the connection-string.

// Replace the values, including <>, with

// the values from your storage account.

public static final String connectStr =

"DefaultEndpointsProtocol=https;" +

"AccountName=;" +

"AccountKey="; +

"EndpointSuffix=core.Chinacloudapi.cn";

将 your_storage_account_name 和 your_storage_account_key 替换为存储帐户的实际值。Replace your_storage_account_name and your_storage_account_key with the actual values for your storage account.

// Configure the connection-string with your values

public static final String storageConnectionString =

"DefaultEndpointsProtocol=http;" +

"AccountName=your_storage_account_name;" +

"AccountKey=your_storage_account_key;" +

"EndpointSuffix=core.Chinacloudapi.cn";

访问 Azure 文件存储Access Azure Files storage

若要访问 Azure 文件存储,请创建一个 ShareClient 对象。To access Azure Files, create a ShareClient object. 使用 ShareClientBuilder 类生成新的 ShareClient 对象。Use the ShareClientBuilder class to build a new ShareClient object.

ShareClient shareClient = new ShareClientBuilder()

.connectionString(connectStr).shareName(shareName)

.buildClient();

若要访问存储帐户,请使用 CloudStorageAccount 对象,将连接字符串传递到其 parse 方法。To access your storage account, use the CloudStorageAccount object, passing the connect

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值