1

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..

Gowri Sundar
  • 669
  • 1
  • 7
  • 15

1 Answers1

0

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
user85421
  • 28,957
  • 10
  • 64
  • 87
  • Hi Carlos. Thanks for good explanation. My doubt is instead of using System.getProperty("FilePath"); , we are trying to use some substitution variable which will get the actual value from the VM Arguments. Say for Example: One of my property is having Key value pair like this "TextfilePath=#filePath#\today\file". So when i try to get this property string filePath=prop.get(TextfilePath); the filePath variable should have value as "C:\file\txt\today\file". But it is having value as "C:filetxt\today\file". – Gowri Sundar Apr 04 '17 at 14:39
  • would be better to have that (and some code) added to the question... it is kind of difficult to guess what `prop` and the `get` method are. – user85421 Apr 04 '17 at 16:17