Home > Enterprise >  What should I keep my path that will work in all systems?
What should I keep my path that will work in all systems?

Time:01-21

try {
            Mockito.when(this.networkStorage.getFile()).thenReturn(new File("d:/temp/nas"));
        } catch (IOException e) {
            e.printStackTrace();
        }

I am getting Error in this line "d:/temp/nas". Actually its working in my windows but not in server. What should I keep my path that will work in all systems?

CodePudding user response:

This does not directly address the question as to 'What value could be inserted into the File() constructor to work universally regardless of the underlying operating system', but could prove to be a compass in the right direction?

Mocking Files in Java - Mock Contents - Mockito - The accepted answer seems to have some helpful comments beneath it as well.

If not, I believe relative paths are what you are looking for (with the project/app directory being considered root or /) - Java - How to create a file in a directory using relative Path

CodePudding user response:

Let me try to answer your question based on my understanding. You are setting some file path to new File() which is working on Windows but not on server(means Linux/Unix flavour). On the linux systems windows path will not work or it will try to search as relative path "<current_directory>/d:/temp/nas". If you want to set the path for any OS then the path should not be hardcoded instead it is suppose to read a enviroment specific config properties and based on the environment the config property value has to be supplied.

  •  Tags:  
  • Related