我使用此代码将文件上传到 azure blob 存储,但是当我尝试使用子目录加载目录时出现错误“遇到 FileNotFoundException:C:\upload\bin”:(访问被拒绝),是加载文件的任何解决方案吗?源目录中的目录?
try {
CloudStorageAccount account = CloudStorageAccount.parse(storageConnectionString);
CloudBlobClient serviceClient = account.createCloudBlobClient();
// Container name must be lower case.
CloudBlobContainer container = serviceClient.getContainerReference(containerName);
container.createIfNotExists();
File source = new File(path);
if (source.list().length > 0) {
for (File file : source.listFiles()) {
CloudBlockBlob blob = container.getBlockBlobReference(file.getName());
if (blob.exists() == false) {
File sourceFile = new File(source + "\\" + file.getName());
blob.upload(new FileInputStream(sourceFile), sourceFile.length());
System.out.println("File " + source + "\\" + file.getName() + " Load to blob storage");
} else System.out.println("File " + source + "\\" + file.getName() + " Already exist in storage");
}
} else System.out.println("In folder " + path + " are no files ");
} catch (FileNotFoundException fileNotFoundException) {
System.out.print("FileNotFoundException encountered: ");
System.out.println(fileNotFoundException.getMessage());
System.exit(-1);
} catch (StorageException storageException) {
System.out.print("StorageException encountered: ");
System.out.println(storageException.getMessage());
System.exit(-1);
} catch (Exception e) {
System.out.print("Exception encountered: ");
System.out.println(e.getMessage());
System.exit(-1);
}
largeQ
相关分类