9

When I use Paths.get() to create a directory I encounter exception below.

java.nio.file.InvalidPathException: Illegal char <:> at index 2: /C:/Users/Desktop/workspaces/sra/emm-be/wsm-kap-api-server/target/test-classes/swagger\swagger.json

This happens when I use the workspace of my Windows machine. For linux, it's working fine.

2 Answers 2

4

Your directory path contains / try using

    Paths.get("C:\\Users\\Desktop\\workspaces\\sra\\emm-be\\wsm-kap-api-server\\target\\test-classes\\swagger\\swagger.json");
Sign up to request clarification or add additional context in comments.

3 Comments

i'm trying to build javafx and don't know how to solve this problem
when / and when to use \\, please explain!!
"/" is used for defining a Unix path, "\" is used for defining a Windows path. But since "\" is used to escape a character, the "\" character will not be take into account. So escaping the escaping character will take the "\" into account
3

You have / before C in Your directory path. If you remove it it should work on Windows too.

 Paths.get(C:/Users/Desktop/workspaces/sra/emm-be/wsm-kap-api-server/target/test-classes/swagger/swagger.json);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.