Linux文件路径分隔符为 / ,windows的文件路径分隔符为 \ ,在开发项目过程中不确定用户使用何种操作系统,就需要自动适配路径
public class FilePathUtil { public static final String FILE_SEPARATOR = System.getProperty("file.separator"); public static String getRealFilePath(String path) { return path.replace("/", FILE_SEPARATOR).replace("\\", FILE_SEPARATOR); } public static String getHttpURLPath(String path) { return path.replace("\\", "/"); } }