[英]Node-Webkit won't open file
First I'd like to say thanks for taking the time to read this. 首先,我要感谢您抽出宝贵的时间阅读本文。 I am trying to open a JSON file that is in the following directory structure:
我正在尝试打开以下目录结构中的JSON文件:
#--> Root Folder
--> App.exe
#--> Configuration
---> JSON File
So I used the Code: 所以我用了代码:
var ConfigFile = "./Configuration/JSON.json";
Followed by: 其次是:
var fs = require('fs');
var file_content = fs.readFileSync(ConfigFile);
var content = JSON.parse(file_content);
// Manipulate the Data
For some odd reason, Node-Webkit seems to be looking for the folder in a Temp Directory located in: 出于某种奇怪的原因,Node-Webkit似乎正在以下位置的Temp目录中查找该文件夹:
C:\\Users\\User\\AppData\\Local\\Temp\\nw9740_14956\\Configuration
C:\\ Users \\ User \\ AppData \\ Local \\ Temp \\ nw9740_14956 \\ Configuration
The file is not there, and thus in the Console I get the following Error: 该文件不存在,因此在控制台中出现以下错误:
Uncaught Error: ENOENT: no such file or directory, open 'C:\\Users\\User\\AppData\\Local\\Temp\\nw9740_14956\\Configuration\\JSON.json'
未捕获的错误:ENOENT:没有此类文件或目录,请打开“ C:\\ Users \\ User \\ AppData \\ Local \\ Temp \\ nw9740_14956 \\ Configuration \\ JSON.json”
I am running Windows (as you can tell), and I would like for fs to pull the file from the Folder (Configuration) that is adjacent to the app.exe. 我正在运行Windows(如您所知),并且我想让fs从与app.exe相邻的Folder(配置)中提取文件。
Any help is appreciated 任何帮助表示赞赏
I've only done this once, so I may be wrong, but it looks like you're bundling your app content into the exe? 我只做过一次,所以我可能错了,但是看来您是将应用程序内容捆绑到exe中? If you do this, node-webkit will extract the app contents into the
%TEMP%
folder and then run the content from there. 如果执行此操作,node-webkit会将应用程序内容提取到
%TEMP%
文件夹中,然后从那里运行内容。
Try checking the command line arguments to see if arg[0]
will point you to the actual node-webkit exe that's running the app. 尝试检查命令行参数以查看
arg[0]
是否将您指向运行该应用程序的实际node-webkit exe。 From there, you should be able to construct a path to your configuration data. 从那里,您应该能够构造一条通往配置数据的路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.