我正在构建我的第一个具有应用程序内容(JSON文件)的电子应用程序。
我的问题是使用 electron-build 包装后,我无法访问应用程序内容。
我将有问题的JSON文件( mvdb.json )添加到了外部资源,并在主流程中解析了路径。
package.json
"build": {
"appId": "com.example.app",
"extraResources": ["mvdb.json"],
"mac": {
"category": "your.app.category.type"
},
"win": { "target": ["portable", "NSIS"]
},
"directories": {
"output": "release"
}
},
main.js
const fs = require('fs');
const isDev = process.env.NODE_ENV !== 'production'
// Load MOVIE Database
const MOVIE_DB_PATH = isDev ? path.join(__dirname, 'mvdb.json') : path.join(process.resourcesPath, 'mvdb.json');
...
fs.readFileSync(MOVIE_DB_PATH)
macOS软件包的内部版本在Contents / Ressources文件夹中具有mvdb.json文件,但是启动后会收到错误消息
Uncaught Exception:
Error: ENOENT, mvdb.json not found in /Users/me/Documents/projects/screenwriters-delight/electron/release/mac/screenwriters-delight.app/Contents/Resources/app.asar
at createError (electron/js2c/asar.js:111:17)
at Object.fs.readFileSync (electron/js2c/asar.js:548:24)
at loadDB ...
有什么建议吗?
答案 0 :(得分:0)
尝试一下
ArrayList<Contact> contacts = new ArrayList<Contact>();
Cursor c = getActivity().getContentResolver().query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,
null, null, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + "asc");
while (c.moveToNext()) {
String contactName = c.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
String phNumber = c.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
Contact ct = new Contact();
ct.setName(contactName);
ct.setNumber(phNumber);
contacts.add(ct);
}
c.close();
您需要将一个文件夹移回。