将我的代码(mac)中的绝对路径更改为我的电脑的相对路径
我有一个 netbeans 项目设置,其中包含指向我的硬盘驱动器上的文件的以下绝对路径。
/Users/Name/NetBeansProjects/DissertationUpnpDevices/src/my/upnpdevices/MSXbox360Device.java
/Users/Name/NetBeansProjects/DissertationUpnpDevices/src/my/upnpdevices/resources/description/MS_Xbox360description.xml
我将把我的项目转移到电脑上,并且我一直在尝试将上述路径转换为相对路径。但这对我来说不起作用。到目前为止我已经尝试过:
private final static String DESCRIPTION_FILE_NAME = "resources\description\MS_Xbox360\description.xml";
private final static String DESCRIPTION_FILE_NAME = "resources\/description\/MS_Xbox360\/description.xml";
但是以上2种尝试都不起作用。他们给我一个“非法转义字符”错误。我还尝试了下面的
private final static String DESCRIPTION_FILE_NAME = "resources/description/MS_Xbox360/description.xml";
private final static String DESCRIPTION_FILE_NAME = "resources//description//MS_Xbox360//description.xml";
private final static String DESCRIPTION_FILE_NAME = "resources\\description\\MS_Xbox360\\description.xml";
private final static String DESCRIPTION_FILE_NAME = "./resources/description/MS_Xbox360/description.xml";
private final static String DESCRIPTION_FILE_NAME = ".//resources//description//MS_Xbox360//description.xml";
private final static String DESCRIPTION_FILE_NAME = ".\\resources\\description\\MS_Xbox360\\description.xml";
这些都给了我“java.io.FileNotFoundException
”。关于如何将绝对 mac URI 转换为我的电脑的相对 URI,还有其他建议吗?电脑上的文件设置在相应的目录中。
I have a netbeans project setup with the following absolute paths pointing to files on my harddrive.
/Users/Name/NetBeansProjects/DissertationUpnpDevices/src/my/upnpdevices/MSXbox360Device.java
/Users/Name/NetBeansProjects/DissertationUpnpDevices/src/my/upnpdevices/resources/description/MS_Xbox360description.xml
I will be moving my project over to a pc and I've been trying to convert the above paths into relative paths. But it's not working out for me. So far I have tried:
private final static String DESCRIPTION_FILE_NAME = "resources\description\MS_Xbox360\description.xml";
private final static String DESCRIPTION_FILE_NAME = "resources\/description\/MS_Xbox360\/description.xml";
But the above 2 attempts don't work. They give me an 'illegal escape character' error. I have also tried the following below
private final static String DESCRIPTION_FILE_NAME = "resources/description/MS_Xbox360/description.xml";
private final static String DESCRIPTION_FILE_NAME = "resources//description//MS_Xbox360//description.xml";
private final static String DESCRIPTION_FILE_NAME = "resources\\description\\MS_Xbox360\\description.xml";
private final static String DESCRIPTION_FILE_NAME = "./resources/description/MS_Xbox360/description.xml";
private final static String DESCRIPTION_FILE_NAME = ".//resources//description//MS_Xbox360//description.xml";
private final static String DESCRIPTION_FILE_NAME = ".\\resources\\description\\MS_Xbox360\\description.xml";
These all give me "java.io.FileNotFoundException
". Any other suggestions as to how I can convert the absolute mac URI to a relative URI for my pc? The files on the pc are setup in the corresponding directories.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
上面的大多数路径应该适合您(特定的“./resources/description/MS_Xbox360/description.xml”)。我刚刚完成一个项目,Mac 版本不喜欢带有“\\”的相对路径,所以我将它们更改为“/”,现在一切正常。另外,
java.io.FileNotFoundException
应该打印出它正在查找的文件。仔细检查错误并确保文件实际存在或不存在。Most of the paths you have above should work fine for you (specific'./resources/description/MS_Xbox360/description.xml'). I just got done with a project and the Mac version didn't like relative paths with '\\' so I changed them to '/' and everything works fine now. Also, the
java.io.FileNotFoundException
should print out what file it's looking for. Inspect the error closely and make sure the file actual does or doesn't exist.