YouTip LogoYouTip

Dir Parent

# Java Example - Get Parent Directory of a File [![Image 3: Java Example](#) Java Example](#) The following example demonstrates using the `file.getParent()` method of the `File` class to get the parent directory of a file: ## Main.java File import java.io.File; public class Main{public static void main(String[]args){File file = new File("C:/File/demo.txt"); String strParentDirectory = file.getParent(); System.out.println("The parent directory of the file is : " + strParentDirectory); }} The output of the above code is: The parent directory of the file is : File [![Image 4: Java Example](#) Java Example](#)
← Postgresql Data TypePostgresql Syntax β†’