0

I need to have the path from a class to a folder. Is there any method that does this?

enter image description here

To be more specific I need the path from MigrationGenerator to the folder migrations so that I can create a file in it

outter.output(migrationDocument, new FileWriter(filePath));

filePath would be the path

Fabio
  • 343
  • 1
  • 6
  • 17
  • This may help :https://stackoverflow.com/questions/1188400/getting-the-path-to-the-directory-of-a-given-class-file – Benkerroum Mohamed Jun 01 '21 at 16:22
  • @B.M it doesn't work because I need a folder ,not a class – Fabio Jun 01 '21 at 16:31
  • I'm pretty certain, that what you describe is not what you want to do. Let's assume you would figure out how to create the file there. As soon as you compile your project and wrap it into a jar, the code will not execute anymore, since your classes exist within the jar file. If you really want to do it, you can use getResource (from the class) and modify the returned `URL` to your needs (e.g., transform to string, replace some values and create a `File` based on the created path). – Philipp Jun 01 '21 at 18:59
  • @Philipp this funcionality isn't supposed to work in a jar – Fabio Jun 02 '21 at 08:14
  • @Fabio: In that case do as I described in the comment, you can use `getResource` to get the `URL` to the resource and do some string manipulation (based on the operation system) and you should get this. – Philipp Jun 04 '21 at 13:34

0 Answers0