You need to enable JavaScript to run this app.
Elastic File Storage

Elastic File Storage

Copy page
Download PDF
Java SDK
Code example
Copy page
Download PDF
Code example
This article provides code examples of the NAS Java SDK for your reference.​
Prerequisites​
Creating file systems​
tip​
For definitions and value ranges of parameters used in the following SDK code, see CreateFileSystem.​
​
package com.volcengine.filenas.examples;​
​
import com.volcengine.ApiClient;​
import com.volcengine.ApiException;​
import com.volcengine.sign.Credentials;​
​
import com.volcengine.filenas.FilenasApi;​
import com.volcengine.filenas.model.*;​
​
public class Main {​
public static FilenasApi 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-guangzhou-a");​
createFileSystemRequest.setFileSystemType("Extreme");​
createFileSystemRequest.setProtocolType("NFS");​
createFileSystemRequest.setChargeType("PayAsYouGo");​
createFileSystemRequest.setCapacity(100);​
// Initiate a request and handle returns or exceptions​
try { ​
CreateFileSystemResponse response = api.createFileSystem(createFileSystemRequest);​
System.out.println(response); ​
} catch (ApiException e) {​
System.out.println(e.getResponseBody());​
}​
}​
​
public static void initClient() {​
// See Initializing the Client for details.​
}​
}​
​
List file systems​
tip​
For definitions and value ranges of parameters used in the following SDK request, see DescribeFileSystems.​
​
package com.volcengine.filenas.examples;​
​
import com.volcengine.ApiClient;​
import com.volcengine.ApiException;​
import com.volcengine.sign.Credentials;​
​
import com.volcengine.filenas.FilenasApi;​
import com.volcengine.filenas.model.*;​
​
public class Main {​
public static FilenasApi api;​
​
public static void main(String[] args) {​
initClient();​
describeFileSystems();​
}​
​
public static void describeFileSystems() {​
DescribeFileSystemsRequest describeFileSystemsRequest = new DescribeFileSystemsRequest();​
describeFileSystemsRequest.setFileSystemIds("enas-cn018413rhre*****"); // File system ID​
// Initiate a request and handle returns or exceptions​
try { ​
DescribeFileSystemsResponse response = api.describeFileSystems(describeFileSystemsRequest);​
System.out.println(response); ​
} catch (ApiException e) {​
System.out.println(e.getResponseBody()); ​
}​
}​
​
public static void initClient() {​
// See Initializing the Client for details.​
}​
}​
​
​
Last updated: 2025.10.28 15:57:50