Catching files on drive C:

0

Using the code:

System.getProperty("user.dir")+"\email\email.properties" 

It picks up from the user

(C:\USUARIO\user\Documents\Netbeans\Projeto\email\email.properties)  

But what if it is in the drive C:\ only?

 (C:\Email\email\email.properties)

How do I System.getProperty get wherever I am?

    
asked by anonymous 03.11.2016 / 20:36

2 answers

1

To get the path of the folder where .jar is running you should use the following code, changing MinhaClasse to the current class name:

MinhaClasse
  .class
  .getProtectionDomain()
  .getCodeSource()
  .getLocation()
  .getPath()
  .getParent() + "\email\email.properties";
    
03.11.2016 / 20:55
1

To return the drive letter where the system is installed

System.getenv("SystemDrive");

SystemDrive is a Windows environment variable, you can capture the value of any of the variables.

    
03.11.2016 / 20:43