Java: Get URI from FilePath

前端 未结 5 926
被撕碎了的回忆
被撕碎了的回忆 2020-12-03 17:11

I\'ve little knowledge of Java. I need to construct a string representation of an URI from FilePath(String) on windows. Sometimes the inputFilePath

5条回答
  •  青春惊慌失措
    2020-12-03 17:46

    class TestPath {
    
        public static void main(String[] args) {
            String brokenPath = "file:/C:/a.txt";
    
            System.out.println(brokenPath);
    
            if (brokenPath.startsWith("file:/")) {
                brokenPath = brokenPath.substring(6,brokenPath.length());
            }
            System.out.println(brokenPath);
        }
    }
    

    Gives output:

    file:/C:/a.txt
    C:/a.txt
    Press any key to continue . . .
    

提交回复
热议问题