赞
踩
import fs from ‘@ohos.file.fs’;
import common from ‘@ohos.app.ability.common’;
async function write(data: string, file: fs.File): Promise {
fs.write(file.fd, data).then((writeLen: number) => {
console.info('write data length is: ’ + writeLen)
}).catch((err) => {
console.error(Failed to write data. Code is ${err.code}, message is ${err.message}
);
})
}
async function testFunc(): Promise {
let context = getContext() as common.UIAbilityContext;
let filePath: string = context.filesDir + “/test.txt”; // 应用文件路径
let file: fs.File = await fs.open(filePath, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
write(‘Hello World!’, file).then(() => {
console.info(‘Succeeded in writing data.’);
}).catch((err) => {
console.error(Failed to write data. Code is ${err.code}, message is ${err.message}
);
})
fs.close(file);
}
testFunc();
@Entry
@Component
struct WebComponent {
build() {
Column() {
Text(“Hello World”)
}
}
}

### 3.多线程并发
#### 声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/714542
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。