Azure file SMB3.0 files sharing Service (5)

Source: Internet
Author: User
Tags cloudfile

?

Managing Azure file Sharing services using Java

?

The Azure File Sharing service provides a variety of ways to access interfaces, including Powershell,.net, Java, Python, and so on, and this chapter focuses on using Java to access Azure file storage.

?

    1. Java Basic Development Environment building, Eclipse plug-in installation, IntelliJ idea plug-in installation, please refer to my documentation:

http://cloudapps.blog.51cto.com/3136598/1772092

  1. With regard to the access connection string, the SDK default connection string is point to global azure, "*.core.windows.net", but the service URL of Azure in China is ". core.chinacloudapi.cn", Therefore, you need to specify Endpointsuffix in the link string.

    ?

  2. about the access protocol of the storage, by default is the HTTPS protocol, but you can also specify as the HTTP protocol, it is generally recommended to use HTTP when accessing storage inside azure, and use HTTPS for encrypted transmission when external access.

    Public staticfinal String storageconnectionstring =

    ???????? "DEFAULTENDPOINTSPROTOCOL=HTTP;" +

    ???????? "Accountname=mystorageacctfile;" +

    ???????? "Accountkey=yourstorageaccountkey;" +

    ???????? "endpointsuffix=core.chinacloudapi.cn";

    ?

    If you need to encrypt the transmission, modify the Defaultendpointsprotocol=https.

    ?

  3. FileShare names are required, for example, all lowercase must be Java inside you will see the following error :

Specific naming rules refer to: https://msdn.microsoft.com/library/azure/dn167011.aspx

  1. You first need to initialize the storage context to get a file access handle:

    Storageaccount = Cloudstorageaccount. Parse(storageconnectionstring);

    ???????? System. Out . println (storageaccount. Getblobendpoint ());

    ???????? ?

    ???????? Cloudfileclient fileclient = storageaccount. createcloudfileclient ();

    ?

  2. To create a new file share:

    Cloudfileshare Share = fileclient. Getsharereference (myfileshare);

    ????????

    if (share. createifnotexists ())

    {

    System. out. println ("New File Share:" + myfileshare +"created!" );

    }

    ?

  3. After the file share creation is complete, we create a directory under the file share:

    Get a reference to the root directory for the share.

    Cloudfiledirectory RootDir = share. getrootdirectoryreference ();

    ????????

    Get a reference to the sampledir directory

    Cloudfiledirectory Sampledir = rootdir. Getdirectoryreference (mydirectory);

    ?

    if (sampledir. createifnotexists ())

    {

    System. out. println ("Sampledir created");

    }

    Else {

    System. out. println ("Sampledir already exists");

}

  1. Uploading or downloading a file in a file share, the download file can be written to the local file through OutStream, and so on, this example directly print out:

    Upload a test file to the sampledir

    Cloudfile cloudfile = sampledir. Getfilereference ("hdinsight.publishsettings");

    ????????

    if (! Cloudfile. Exists ())

    {

    ???? cloudfile. Uploadfromfile (testfilepath);

    }

    Else

    {

    ???? //download file if exists

    ???? System. Out . println (cloudfile. Downloadtext ());

    }

  2. The following example shows how to delete a file, delete a directory, please note that when the directory is deleted, the directory must not have any files, or will be error:

    ?

    Cloudfile cloudfile = sampledir. Getfilereference (testfilename);

???? //delete specified file

???? if ( cloudfile. deleteifexists ())

{

???? System. out. println (testfilename + "is deleted!" );

????????

}

?

Get a reference to the root directory for the share.

Cloudfiledirectory RootDir = share. getrootdirectoryreference ();

???????? ?

Get a reference to the sampledir directory

Cloudfiledirectory Sampledir = rootdir. Getdirectoryreference (mydirectory);

Delete the Directory

if ( sampledir. deleteifexists ())

{

???? System. out. println ("Directory"+ sampledir +"is deleted!" );

}

?

About when you call the Azure file interface, use the https link to link the Defaultendpointsprotocol is set to https, You may encounter the following error:

?

even if you are using the latest Azure China of the wosign of the certificate, the above problems can also occur, specific reasons and Azure China no matter, you understand:) The solution please refer to my blog:

?

http://cloudapps.blog.51cto.com/3136598/1744342

?

Azure file SMB3.0 files sharing Service (5)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.