file path Windows format to java format

后端 未结 5 735
走了就别回头了
走了就别回头了 2020-11-30 03:49

I need to convert the file path in windows say C:\\Documents and Settings\\Manoj\\Desktop for java as C:/Documents and Settings/Manoj/Desktop .

Is there any utilit

5条回答
  •  攒了一身酷
    2020-11-30 04:46

    Java 7 and up supports the Path class (in java.nio package). You can use this class to convert a string-path to one that works for your current OS.

    Using:

    Paths.get("\\folder\\subfolder").toString()
    

    on a Unix machine, will give you /folder/subfolder. Also works the other way around.

    https://docs.oracle.com/javase/tutorial/essential/io/pathOps.html

提交回复
热议问题