Grab Files on Drive C:

Asked

Viewed 156 times

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’s in the unit C:\ only?

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

How do I make for the System.getProperty get wherever you are?

  • 1

    Return new File(Minhaclasse.class.getProtectionDomain(). getCodeSource(). getLocation(). toURI(). getPath());

2 answers

1

To return the letter of drive where the system is installed

System.getenv("SystemDrive");

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

1


To take the path to the folder where the . jar is running you must use the following code, swapping MinhaClasse by the name of the current class:

MinhaClasse
  .class
  .getProtectionDomain()
  .getCodeSource()
  .getLocation()
  .getPath()
  .getParent() + "\\email\\email.properties";
  • beauty, we are on the way rs. It is that from the local folder of the file jar grab another file of type properties. c: project folder file.properties. I’m trying here. And the jar is in C: project project.jar

  • Just you concatenate the path of the folder... In a few minutes I edit my answer with this

  • The project is looking like this: /D:/Documents/Netbeansprojects/Enviar email/build/classes/&#X;in unit C: is getting c: project project.jar

  • managed to resolve. Actually it was just me who was trying to run from the wrong user. In cmd I gave the cd commands .. until I got to C: project and then I gave the java -jar project and it finally worked. My object was to give the java -jar command from anywhere and it recognize the location

  • Don’t worry. If you could just dial in an answer, I’d appreciate it. Later I will edit with the part of adding the rest of the path and a little more explanations to be more complete

  • 1

    Blz. Thank you very much!

  • All right, buddy, I added the path!

  • Um. Ah ta. I’ll test

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.