无法从nativescrypt中的文件中读取

时间:2015-11-10 12:29:35

标签: telerik readfile nativescript

我尝试在文件中写一些字符串然后读取它们,但是有错误消息无法访问锁定文件。在iphone和android上测试过。

page.xml

<Page xmlns="http://www.nativescript.org/tns.xsd" loaded="pageLoaded" actionBarHidden="true">
<StackLayout>
<Label text="Tap the button" id="label"/>
<Button text="TAP" id="btn" />
</StackLayout>
</Page>

page.js

var frameModule = require("ui/frame");
var view = require("ui/core/view");
var dialogs = require("ui/dialogs");
var fs = require("file-system");

function pageLoaded(args) {
   var page = args.object;

   var button = view.getViewById(page, "btn");
   var label = view.getViewById(page, "label");

   button.on("tap", function (){
        var documents = fs.knownFolders.documents();
        var myFile = documents.getFile("Test_Write.txt");

   myFile.writeText("Something")
        .then(function () {
        myFile.readText()
            .then(function (content) {
            label.text = content;

        }, function (error) {
            label.text = error;
        });
    }, function (error) {
        label.text = error;
    });
   });
}
   exports.pageLoaded = pageLoaded;

1 个答案:

答案 0 :(得分:1)

write方法锁定但永远不会解锁文件。

This has been addressed with the following pull request