在我的函数中,我想打开新创建的文件,并在these instructions之后将数据写入其中。这是我的代码:
function writeDataToFile(newFile) {
try {
console.log("[Matin] writeDataToFile started...");
if(newFile != null) {
newFile.openStream('a', onOpenStream, function(error) {
console.log("[Matin] Could not create the file.");
console(error);
}, "UTF-8");
function onOpenStream(fs) {
console.log("[Matin] New file is opened.");
fs.write("Hello ---------- Data Goes Here ----------");
fs.write(JSON.stringify(dataToFile));
console.log("[Matin] this is the data to be written>>>\n" + JSON.stringify(dataToFile));
fs.close();
dataToFile = null;
newFile = null;
console.log("[Matin] Data is written into the file, and temporal variables are set to null.");
};
} else {
console.log("[Matin] no file here to write into!...");
}
console.log("[Matin] writeDataToFile ended!!!");
} catch (exception) {
console.log("[Matin] [Exception] " + exception.message);
}
}
这是我从执行该功能获得的日志。一切都很好看:
js/managers/exportManager.js (295) :[Matin] writeDataToFile started...
js/managers/exportManager.js (314) :[Matin] writeDataToFile ended!!!
js/managers/exportManager.js (303) :[Matin] New file is opened.
js/managers/exportManager.js (305) :[Matin] this is the data to be written>>>
[{"steps":null,"heartrate":null,"accelX":"-0.9709117078781128","accelY":"3.4513116836547852","accelZ":"8.347122440338135",...]
js/managers/exportManager.js (309) :[Matin] Data is written into the file, and temporal variables are set to null.
但问题是,当我查看文件时,没有任何内容写入其中!该文件中没有数据。甚至不是Hello ---------- Data Goes Here ----------
行。
可能是什么原因?谢谢。
答案 0 :(得分:0)
我不知道你的具体案例,我也不知道Tizen,但我希望可以帮助我的这个轶事。
文件权限:我在基于Linux的系统上开发之前遇到了一个问题,创建该文件的用户与正在执行该程序的用户不同,因为该程序没有正确的写入权限。它只有读取权限。因此看起来一切正常,但实际上它没有写,因为程序没有对文件的写权限。