[英]Unable to find file (getResource)
I have a following project structure: 我有以下项目结构:
I want to open file user_config.db in SQLiteConnector class and i use the following code: 我想在SQLiteConnector类中打开文件user_config.db ,我使用以下代码:
public boolean isDatabaseFileExist(){
File databaseFile = new File(getClass().getResource("/remotecontrolserverfx/databases/user_config.db").toString());
return databaseFile.exists();
}
And it always returns false
. 并且它总是返回
false
。 How to fix? 怎么修?
Thanks in advance. 提前致谢。 Regards...
问候...
Try this; 尝试这个; Note that leading "/" is removed from file path.
请注意,从文件路径中删除了前导“ /”。
public boolean isDatabaseFileExist(){
return this.getClass().getClassLoader().getResource("remotecontrolserverfx/databases/user_config.db")!=null;
}
If you want to get the File
object; 如果要获取
File
对象;
File databaseFile = new File(this.getClass().getClassLoader().getResource("remotecontrolserverfx/databases/user_config.db").getFile());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.