COMPUTER LANGUAGES HTML,C,C++.JAVA,.NET AND MULTIMEDIA basics and programs click home button
JAVA EXAMPLES PARENT DIRECTORY
Java Examples - Parent Directory
Problem Description:
How to get the parent directory of a file?
Solution:
Following example shows how to get the parent directory of a file by the use of file.getParent() method of File class.
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("Parent directory is : "
+ strParentDirectory);
}
}
Result:
The above code sample will produce the following result.
Parent directory is : File
No comments:
Post a Comment