如何使用 Ballerina 创建 .txt 文件?
How to create a .txt file with Ballerina?
如何使用 Ballerina 编程语言创建文本文件?定义文件的文件名和路径。
您可以使用 ballerina/io
包来创建文件。
这里是一个使用 io:ByteChannel
的例子
import ballerina/io;
function main (string... args) {
io:ByteChannel byteChannel = io:openFile("/absolute/path/to/file.txt", io:WRITE); // If the file does not exist it will be created
string someContent = "some content";
byte[] content = someContent.toByteArray("UTF-8");
var writeResult = byteChannel.write(content, 0);
io:print(writeResult);
}
您可以提供相对路径而不是绝对路径。在这种情况下,txt 文件将创建在相对于您 运行 芭蕾舞演员所在位置的位置。
如何使用 Ballerina 编程语言创建文本文件?定义文件的文件名和路径。
您可以使用 ballerina/io
包来创建文件。
这里是一个使用 io:ByteChannel
import ballerina/io;
function main (string... args) {
io:ByteChannel byteChannel = io:openFile("/absolute/path/to/file.txt", io:WRITE); // If the file does not exist it will be created
string someContent = "some content";
byte[] content = someContent.toByteArray("UTF-8");
var writeResult = byteChannel.write(content, 0);
io:print(writeResult);
}
您可以提供相对路径而不是绝对路径。在这种情况下,txt 文件将创建在相对于您 运行 芭蕾舞演员所在位置的位置。