Search code examples
javafile-ioionio

Java IO API: how to get into file subdirectory?


I have a File pointing to a base dir:

File baseDir = new File("c:\\baseDir");

now I want to "go into a subdir":

File subDir = new File("c:\\baseDir\\subDir");

I only found how I can do it via strings concatenation. But is there an API function to do the job?


Solution

  • There is one of the overloaded constructors serving the purpose:

    > File(File parent, String child)
    
    Creates a new File instance from a parent abstract pathname and a child pathname string.