You need to enable JavaScript to run this app.
导航
代码示例
最近更新时间:2023.12.18 14:39:24首次发布时间:2023.12.18 14:39:24

本文介绍 文件存储 vePFS Java SDK 的代码示例供您参考。

前提条件

  1. 下载安装 SDK

  2. 初始化客户端

创建文件系统

说明

关于下述 SDK 代码中所使用参数的定义、取值范围等信息,请参见 CreateFileSystem

package com.volcengine.vepfs.examples;

import com.volcengine.ApiClient;
import com.volcengine.ApiException;
import com.volcengine.sign.Credentials;

import com.volcengine.vepfs.VepfsApi;
import com.volcengine.vepfs.model.*;

public class Main {
    public static VepfsApi api;

    public static void main(String[] args) {
        initClient();
        createFileSystem();
    }
    
    public static void createFileSystem() {
    	  CreateFileSystemRequest createFileSystemRequest = new CreateFileSystemRequest();
    	  createFileSystemRequest.setFileSystemName("java_sdk_test");
        createFileSystemRequest.setZoneId("cn-beijing-a");
        createFileSystemRequest.setFileSystemType("VePFS");
        createFileSystemRequest.setProtocolType("VePFS");
        createFileSystemRequest.setChargeType("PayAsYouGo");
        createFileSystemRequest.setCapacity(6);
        createFileSystemRequest.setStoreType("Advance_100");
        createFileSystemRequest.setVpcId("vpc-11w4ygf1zls7*************");
        createFileSystemRequest.setSubnetId("subnet-11wlfzpho**************");

    	  // 发起请求并处理返回或异常
    	  try { 
    	      CreateFileSystemResponse response = api.createFileSystem(createFileSystemRequest);
    	      System.out.println(response); 
    	  } catch (ApiException e) {
    	      System.out.println(e.getResponseBody());
    	  }
    }
    
    public static void initClient() {
       // 详见初始化客户端部分
    }
}

列举文件系统

说明

关于下述 SDK 请求中所使用参数的定义、取值范围等信息,请参见 DescribeFileSystems

package com.volcengine.vepfs.examples;

import com.volcengine.ApiClient;
import com.volcengine.ApiException;
import com.volcengine.sign.Credentials;

import com.volcengine.vepfs.VepfsApi;
import com.volcengine.vepfs.model.*;

public class Main {
    public static VepfsApi api;

    public static void main(String[] args) {
        initClient();
        describeFileSystems();
    }
    
    public static void describeFileSystems() {
    	  DescribeFileSystemsRequest describeFileSystemsRequest = new DescribeFileSystemsRequest();
    	  describeFileSystemsRequest.setFileSystemIds("vepfs-cn**************"); // 文件系统 ID
    	  // 发起请求并处理返回或异常
    	  try { 
    	      DescribeFileSystemsResponse response = api.describeFileSystems(describeFileSystemsRequest);
    	      System.out.println(response); 
    	  } catch (ApiException e) {
    	      System.out.println(e.getResponseBody()); 
    	  }
    }
    
    public static void initClient() {
        // 详见初始化客户端部分
    }
}