Search code examples
javar.java-file

Create file without listing full path - Java


At the moment I create a file like this:

new File("C:\\Users\\user\\Projects\\javaProject\\src\\com\\javaProject\\package\\file.xml");

So far listing the whole path is the only way I can get the file to be create inside 'package' otherwise if I just use:

new File("file.xml");

it just gets created in the source directory and if I use:

new File("package\\file.xml");

it just throws errors


Solution

  • Have you tried using a relative path?

    new File("com\\javaProject\\package\\file.xml");