《鸿蒙开发-答案之书》将系统路径文件复制到沙盒工具类
如果没有问存储权限,是不能访问系统文件的。但是可以把系统文件拷贝到你app的沙盒里面,就可以访问了。沙盒本质就是你app缓存的目录
直接上代码:
public static async copyToSandbox(uris: Array<string>) : Promise<Array<string>> {
let targetList = new Array<string>();
if (!ArrayChecker.isValid(uris)) {
return targetList;
}
for (let u of uris) {
let file = await fs.open(u, fs.OpenMode.READ_ONLY);
let targetPath = getContext().cacheDir + "/" + file.name;
fs.closeSync(file);
targetPath = "file://" + targetPath;
await fs.copy(u, targetPath);
targetList.push(targetPath);
}
return targetList;
}
标签:复制到,fs,鸿蒙,let,file,沙盒,targetPath,targetList
From: https://blog.csdn.net/u010074743/article/details/144985478