简体   繁体   English

文件API写入文件不起作用三星智能电视SDK

[英]File API writing file doesn't work Samsung smart tv SDK

I have this javascript code which makes possible writing in a file 我有这个JavaScript代码,可以在文件中写入

{

     var fileSystemObj = new FileSystem();
     var fileObj = fileSystemObj.openCommonFile(curWidget.id + 
                                           ‘/testFile.data’, ‘w’);
     fileObj.writeLine(‘something to write.’);
     fileSystemObj.closeCommonFile(fileObj);

}

but it doesn't work. 但这不起作用。 Doesn't even display any error! 甚至不显示任何错误!

samsung developer forum (you may not see unless you sign in... ) I am quoting it. 三星开发人员论坛(除非您登录否则可能看不到...)

    case tvKey.KEY_RED:
  alert('RED BUTTON!');
  alert('CWID: '+curWidget.id);
  try {
    var fileSystemObj = new FileSystem();
    var fileObj = fileSystemObj.openCommonFile(curWidget.id+'/testFile.data','w');
    fileObj.writeLine('something to write.');
    fileSystemObj.closeCommonFile(fileObj);
  } catch (e) {
    alert('Error: file handling: '+e);
  }
  break;

lead to error: alert() : Error: file handling: TypeError: 'null' is not an object (evaluating 'fileObj.writeLine') Reading cause same problem. 导致错误:alert():错误:文件处理:TypeError:'null'不是对象(评估'fileObj.writeLine')读取引起相同的问题。

and solution accepted in that link is: 该链接接受的解决方案是:

I suppose that problem is that you have to create common dir (if does not exist ) at first : 我想这个问题是,您必须首先创建公用目录(如果不存在):

var fileObj = fileSystemObj.openCommonFile(filePath, 'w');
if(!fileObj){
var bValid = fileSystemObj.isValidCommonPath(curWidget.id); 
if (!bValid) { 
        fileSystemObj.createCommonDir(curWidget.id);    
}
}
fileObj = fileSystemObj.openCommonFile(filePath, 'w');
fileObj.writeLine('something to write.');
fileSystemObj.closeCommonFile(fileObj);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM