Fix the compatibility problem of ConfigUtil for Windows environment (#903)
This commit is contained in:
parent
4a9543fd1f
commit
326dd4434d
|
|
@ -45,7 +45,7 @@ public final class ConfigUtil {
|
||||||
*/
|
*/
|
||||||
public static Properties loadProperties(String fileName) {
|
public static Properties loadProperties(String fileName) {
|
||||||
if (StringUtil.isNotBlank(fileName)) {
|
if (StringUtil.isNotBlank(fileName)) {
|
||||||
if (fileName.startsWith(File.separator)) {
|
if (absolutePathStart(fileName)) {
|
||||||
return loadPropertiesFromAbsoluteFile(fileName);
|
return loadPropertiesFromAbsoluteFile(fileName);
|
||||||
} else if (fileName.startsWith(CLASSPATH_FILE_FLAG)) {
|
} else if (fileName.startsWith(CLASSPATH_FILE_FLAG)) {
|
||||||
return loadPropertiesFromClasspathFile(fileName);
|
return loadPropertiesFromClasspathFile(fileName);
|
||||||
|
|
@ -76,6 +76,16 @@ public final class ConfigUtil {
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean absolutePathStart(String path) {
|
||||||
|
File[] files = File.listRoots();
|
||||||
|
for (File file : files) {
|
||||||
|
if (path.startsWith(file.getPath())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private static Properties loadPropertiesFromClasspathFile(String fileName) {
|
private static Properties loadPropertiesFromClasspathFile(String fileName) {
|
||||||
fileName = fileName.substring(CLASSPATH_FILE_FLAG.length()).trim();
|
fileName = fileName.substring(CLASSPATH_FILE_FLAG.length()).trim();
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ public class ConfigUtilTest {
|
||||||
}
|
}
|
||||||
BufferedWriter out = new BufferedWriter(new FileWriter(file));
|
BufferedWriter out = new BufferedWriter(new FileWriter(file));
|
||||||
out.write(LOG_OUTPUT_TYPE + "=" + logOutputType);
|
out.write(LOG_OUTPUT_TYPE + "=" + logOutputType);
|
||||||
out.write("\n");
|
out.write(System.getProperty("line.separator"));
|
||||||
out.write(LOG_DIR + "=" + dir);
|
out.write(LOG_DIR + "=" + dir);
|
||||||
out.flush();
|
out.flush();
|
||||||
out.close();
|
out.close();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue