1说明:
window与Linux中的路径符号是不一样的。工程发布到服务器中时,若是路径兼容没有考虑到,会导致错误。
2代码演示:
private static final String Windows_Seprater = "\\";
private static final String Linux_Seprater = "/";
...
private String getPath() {
path = this.getClass().getResource("/").getPath();
if (Windows_Seprater.equals(File.separator)) {
path = path.substring(1, path.indexOf("/classes"));
path = path.replace("/", "\\");
}
if (Linux_Seprater.equals(File.separator)) {
path = path.substring(0, path.indexOf("/classes"));
path = path.replace("\\", "/");
}
path = path + seprater + "software";
return path;
}