JAVA自動適配Linux與Windows文件路徑分隔符


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("\\", "/"); } } 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM