Eclipse VM arguments picking directory name without separator

2.9k Views Asked by At

I am setting the VM arguments in eclipse as -DFilePath="C:\file\txt" But while calling this #FilePath# in java it is giving output as C:filetxt instead of C:\file\txt. This is resulting in file not found exception. Can anyone please help me on this..

1

There are 1 best solutions below

2
On

The problem must be in how you are "calling this #FilePath#".

I tested with following code:

package test;

import java.io.File;

public class EnvPath {

    public static void main(String[] args) {
        String path = System.getProperty("FilePath");
        System.out.println("Prop: " + path);
        File file = new File(path);
        System.out.println("File: " + file);
    }
}

Started from Eclipse, as you described, or with java -DFilePath="C:\file\txt" test.EnvPath using Windows Command Prompt and using GNU bash - it always produces:

Prop: C:\file\txt
File: C:\file\txt