Java NIO file path issue

前端 未结 8 2055
臣服心动
臣服心动 2020-12-01 11:36

I used the following code to get the path

Path errorFilePath = FileSystems.getDefault().getPath(errorFile);

When I try to move

8条回答
  •  盖世英雄少女心
    2020-12-01 12:22

    Normal Windows Environment

    Disclaimer: I haven't tested this on a normal windows environment.

    "\\C:\\" needs to be "C:\\"

    final Path errorFilePath = Paths.get(FileSystems.getDefault().getPath(errorFile).toString().replace("\\C:\\","C:\\"));
    

    Linux-Like Windows Environment

    My Windows box has a Linux-Like environment so I had to change "/C:/" to be "C:\\".

    This code was tested to work on a Linux-Like Windows Environment:

    final Path errorFilePath = Paths.get(FileSystems.getDefault().getPath(errorFile).toString().replace("/C:/","C:\\"));
    

提交回复
热议问题