2012-03-15 21 views
0

我有这样的javascript代码,这使得可以书面文件文件API写文件不起作用三星智能电视SDK

{ 

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

} 

,但它不工作。甚至不显示任何错误!

+0

你的意思是[这个文件系统草案(http://www.w3.org/TR/file-system -API /)?在浏览器中几乎没有任何支持。三星电视运行什么浏览器?它确实支持FileSystem对象吗? – Rup 2012-03-15 16:07:54

+1

@Rup支持根据开发人员指南http://freethetv2011.s3.amazonaws.com/App_Development_Guide_for_Samsung_Smart_TV%5BV1.20%5D%5B1%5D.pdf – antyrat 2012-03-15 16:10:47

+1

@star尝试添加'try..catch'语句并提醒结果 – antyrat 2012-03-15 16:13:27

回答

1

samsung developer forum (you may not see unless you sign in...) 我在引用它。

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.

和解决方案在接受链接是:

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); 
+0

已更新答案以包含SamSung的代码片段 – 2012-06-18 09:38:40