1

I have the following piece of code:

class Train{
   static{
        InputStream inpStr = Train.class.getClassLoader().getResourceAsStream("ABC.properties");
        Properties props = new Properties();
        props.load(inpStr);
   }
}

I want to know the absolute file path of this file ABC.properties, i.e from where inpStr is reading it? Through debugging, I realised the object assigned to inpStr is actually of java.io.ByteArrayInputStream. But I unable to find a way to get the abolute file path. Please help

Zeus
  • 319
  • 2
  • 13

1 Answers1

1

First you need to get resource, not resourceAsStream:

URL resource = Train.class.getClassLoader().getResource("ABC.properties");

Then you get the path

Path path = Paths.get(resource.toURI());

And finally you can display the absolutePath

System.out.println(path.toAbsolutePath().toString());
IQbrod
  • 2,060
  • 1
  • 6
  • 28