Search code examples
javajsfmanaged-bean

Find relative path of java application


I have read all the other questions related to this in StackOverflow and I did not find any clear response. To cut it short, I have an application that will store some files in a directory that I will use than to process them. I have intentions of moving my app in different places (other computers) so I need to have a relative path to work with so that I will not change that in each time. Does anyone know how to get the relative path of the application (not the full path) so that I could use in this case? If what I am asking is not wright please tell me another way to achieve what I need. Thank you


Solution

  • Just use "./".

    No matter what directory your application has been launched from, "./" will always return that directory.

    For example:

    new File("./") will return a file object pointed at the directory your java application has been launched from

    new File("./myDirectory") will return a file object pointed at the myDirectory folder located in the directory your java application has been launched from