nativescript - (Nativescript) 将文件从 bundle 复制到文档目录

标签 nativescript

有没有办法将文件从源应用程序文件夹中的任何位置复制到设备的文档目录?我一直在查看文件系统插件文档,但找不到有关此主题的任何内容。

最佳答案

仔细看看cookbook docs,似乎您可以创建对设备文档文件夹的引用,如下所示:

var documents = fs.knownFolders.documents();

然后,您可以使用类似这样的内容从您的应用程序获取文件(?)。其中路径是对应用程序中捆绑的文件的引用:

var myFile = fs.File.fromPath(path);

所以你可以这样做:

// Writing text to the file.
myFile.readText()
        .then(function (content) {
            // Successfully read the file's content.
        documents.writeText(content)
           .then(function () {
              // Succeeded writing to the file.
           }, function (error) {
              // Failed to write to the file.
           });
        }, function (error) {
            // Failed to read from the file.
        });

关于nativescript - (Nativescript) 将文件从 bundle 复制到文档目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38673605/

相关文章:

android - Nativescript 在 debug.apk 上构建发布 apk 成功时失败

nativescript - 商店没有供应商!注入(inject)错误

javascript - Nativescript ListView在页面加载时加载更多内容

html - 我可以在 Nativescript 中将 iOS 选项卡 View 放在顶部吗?

nativescript - 如何在 NativeScript 中更改进度组件的高度

android - native 脚本错误。在列表模板中找到多个 View

android - 如何在 NativeScript 中更改应用程序名称

android - tns-platform-declarations 的 nativescript-carousel 错误

ios - NativeScript 静态库实现如何生成 TypeScript 声明

ios - 如何在 iOS 上编辑 NativeScript-Angular RadDataForm UIStepper?