仅作代码备份只用
private static final String WINDOWS_PREFIX = "\\";
private static final String LINUX_PREFIX = "/";
private static final String PATH_SEPARATOR = "\\\\";
private String getAbsolutePath(String path) {
if (WINDOWS_PREFIX.equals(File.separator)) {
path = path.replaceAll(LINUX_PREFIX, PATH_SEPARATOR);
if (path.substring(0, 1).equals(WINDOWS_PREFIX)) {
path = path.substring(1);
}
}
if (LINUX_PREFIX.equals(File.separator)) {
path = path.replaceAll(PATH_SEPARATOR, LINUX_PREFIX);
}
return path;
}
public static void main(String[] args) {
System.out.println(getAbsolutePath(ResourceUtils.getURL("classpath:").toString()));
}