azure java_Azure File服务(5): Java开发

使用Java管理Azure文件共享服务

Azure文件共享服务提供了多种方式的访问接口,包括Powershell,.Net, Java, Python等等,本章主要介绍如何使用Java来访问Azure File存储。

Java基本开发环境的搭建,Eclipse的插件安装,IntelliJ IDEA的插件安装,请参考我的文档:关于访问连接串,SDK默认的连接串是指向global Azure的,即"*.core.windows.net",但中国区的Azure的访问的服务URL是".core.chinacloudapi.cn",所以需要在链接字符串中指定EndpointSuffix。

关于存储的访问协议,默认情况下是https协议,但你也可以指定为http协议,一般建议在Azure内部访问存储的时候使用http,而在外部访问的时候使用https进行加密传输。

publicstaticfinalString storageConnectionString=

"DefaultEndpointsProtocol=http;"+

"AccountName=mystorageacctfile;"+

"AccountKey=YOURStorageAccountKey;"+

"EndpointSuffix=core.chinacloudapi.cn";

如果需要进行加密传输,修改DefaultEndpointsProtocol=https.

Fileshare的名字命名是有要求的,例如必须全部小写等,否则在Java里面你会看到如下错误:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是Java语言的Azure Blob Storage本地文件上传示例: 1. 首先需要安装Azure Blob Storage SDK。可以在Maven中添加以下依赖项: ``` <dependency> <groupId>com.microsoft.azure</groupId> <artifactId>azure-storage</artifactId> <version>10.0.3</version> </dependency> ``` 2. 引用以下包: ``` import com.microsoft.azure.storage.CloudStorageAccount; import com.microsoft.azure.storage.blob.CloudBlobClient; import com.microsoft.azure.storage.blob.CloudBlobContainer; import com.microsoft.azure.storage.blob.CloudBlockBlob; ``` 3. 建立Blob服务连接: ``` String storageConnectionString = "DefaultEndpointsProtocol=https;AccountName=<your_account_name_here>;AccountKey=<your_account_key_here>;EndpointSuffix=core.windows.net"; CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString); CloudBlobClient blobClient = storageAccount.createCloudBlobClient(); ``` 4. 获取容器引用: ``` CloudBlobContainer container = blobClient.getContainerReference("your_container_name_here"); ``` 5. 创建容器(如果不存在): ``` container.createIfNotExists(); ``` 6. 获取Blob引用: ``` CloudBlockBlob blob = container.getBlockBlobReference("your_blob_name_here"); ``` 7. 上传本地文件: ``` File file = new File("your_local_file_path_here"); blob.upload(new FileInputStream(file), file.length()); ``` 以上是一个基本的本地文件上传示例,你可以根据自己的需求进行修改和扩展。注意替换示例中的 `<your_account_name_here>`、`<your_account_key_here>`、`your_container_name_here`、`your_blob_name_here`、`your_local_file_path_here`为真实的值。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值