blob: 5f5a1e08656812a9ed62f957a886d4f4c633cb46 (
plain) (
blame)
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
|
package util;
import java.io.File;
import org.apache.log4j.Logger;
public class FileSystem {
private static final Logger LOGGER = Logger.getLogger(FileSystem.class);
public static String getRelativePath(File absolutePath, File parentDir) {
String file;
String dir;
try {
file = absolutePath.getCanonicalPath();
dir = parentDir.getCanonicalPath() + File.separator;
} catch (Exception e) {
LOGGER.error("Could not get relative path for " + absolutePath.toString(), e);
return null;
}
if (!file.startsWith(dir))
return null;
return file.substring(dir.length());
}
}
|