File path names for Windows and Linux

后端 未结 2 1647
闹比i
闹比i 2020-12-10 15:04

Below is a path to my Windows directory. Normally the path should have \\ instead of // but both seem to work.

String WinDir = \"C://trash//blah//blah\";
         


        
2条回答
  •  既然无缘
    2020-12-10 15:41

    With java.nio.path, you even better get an independent OS path without any concern about path delimiter.

    public class PathsGetMethod {
        public static void main(String[] args) {
            Path path = Paths.get("C:\\Users\\conta\\OneDrive\\", "desktop", "data");
            System.out.println(path); 
            //C:\Users\conta\OneDrive\desktop\data
        }
    }
    

提交回复
热议问题