我在Windows 10上,尝试使用Tabris.js读写一个简单的文本文件
console.log报告:
/local/src/hello.txt
Error: No such file or directory: /local/src/hello.txt代码:
const {fs} = require('tabris');
let path=fs.filesDir + '/src/hello.txt'
console.log(path)
fs.writeFile(path, 'Hello World!', 'ascii')
.then(() => console.log('file written:', path))
.catch(err => console.error(err));Tabris.js参考资料:
澄清:
如果我能做到这一点,我将做一个非常简单的教程。
Tabris运行良好,没有任何问题,但是我无法读取或写入文件,因为查找该文件时出错。我已经尝试了十几种组合的东西,用点,没有点等等-没有运气。尝试了__directory、fs.filesDir等等,这样路径就不会被硬编码,什么也不起作用。
Tabris文件夹和文件位置:
C:\Users\Rob Acer Aspire 3\junk\package.json
C:\Users\Rob Acer Aspire 3\junk\src\app.jsTabris 2.4
谢谢你的帮助。
更新-开始工作了.
下面的代码似乎正在起作用。我假设hello.txt会在我的/src文件夹中,或者至少我的tabris文件夹叫做“垃圾”,但是它正在写到另一个文件夹。似乎文档在这一点上是正确的,因为他们说的路径的目录,应用程序可能用来存储持久文件。
let file = fs.filesDir + '/hello.txt';
// ok, this works.. > file written: /local/hello.txt
// and is located in:
// C:\Users\Rob Acer Aspire 3\AppData\Local\Packages\EclipseSource.Tabris.js2_en185yn5qwkmw\LocalState\hello.txt我不明白/local/hello.txt的真正意思
所以,我的问题被回答了,谢谢你的帮助。
抢夺
发布于 2018-03-24 15:49:12
在窗户上
"/local/src/hello.txt 将相当于
"c:\local\src\hello.txt"为了使路径在您的应用程序目录中开始,您应该在当前应用程序目录中使用"./“来标记路径,因此在您的情况下
"./local/src/hello.txt" 如果您想返回一个目录,请以"../“开头
发布于 2018-03-30 17:42:50
它现在起作用了,下面有代码。我假设hello.txt会在我的/src文件夹中,或者至少我的tabris文件夹叫做“垃圾”,但是它正在写到另一个文件夹。在这一点上,文档似乎是正确的,因为他们说:
应用程序可用来存储持久文件的目录的路径。
let file = fs.filesDir + '/hello.txt';
// ok, this works.. > file written: /local/hello.txt
// and is located in:
// C:\Users\Rob Acer Aspire 3\AppData\Local\Packages\EclipseSource.Tabris.js2_en185yn5qwkmw\LocalState\hello.txt我不明白/local/hello.txt的真正意思
https://stackoverflow.com/questions/49466447
复制相似问题