-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPathUtils.java
More file actions
44 lines (35 loc) · 1.24 KB
/
PathUtils.java
File metadata and controls
44 lines (35 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package io.github.linwancen.util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
public class PathUtils {
private PathUtils() {}
private static final Logger LOG = LoggerFactory.getLogger(PathUtils.class);
public static final String CLASS_PATH;
static {
@SuppressWarnings("ConstantConditions")
String path = PathUtils.class.getResource("/").getPath();
try {
path = URLDecoder.decode(path, "UTF-8");
} catch (Exception ignored) {
}
CLASS_PATH = path;
}
public static String canonicalPath(File file) {
try {
return file.getCanonicalPath().replace('\\', '/');
} catch (IOException e) {
String path = file.getAbsolutePath().replace('\\', '/');
LOG.warn("getCanonicalPath IOException {}\nuse AbsolutePath file:///{}",
e.getLocalizedMessage(), path, e);
return path;
}
}
public static String dirSpaceName(String dirFile) {
int nameIndex = dirFile.lastIndexOf('/') + 1;
String dir = dirFile.substring(0, nameIndex);
String name = dirFile.substring(nameIndex);
return dir + " " + name;
}
}