import java.io.File; public class GetFileExample { public static void main(String[] args) { String path = "/Users/Documents/MyFile.txt"; File file = new File(path); System.out.println("File object: " + file); } }
import java.io.File; public class GetFileExample { public static void main(String[] args) { String path = "/Users/Documents/"; File directory = new File(path); System.out.println("File object: " + directory); } }Brief Description: The above code examples demonstrate how to use the getFile() method to get the file object of a specific file or directory. The method takes a string argument as a path name and returns the file object of a file or directory specified by the path name. The first example illustrates how to get the file object of a file. The second example demonstrates how to get the file object of a directory. Package Library: The examples above use the Java IO package, which is a built-in package library in Java.