Java 实例 - 获取文件的上级目录
以下实例演示了使用 File 类的 file.getParent() 方法来获取文件的上级目录:
Main.java 文件
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("文件的上级目录为 : " + strParentDirectory);
}
}
public class Main {
public static void main(String[] args) {
File file = new File("C:/File/demo.txt");
String strParentDirectory = file.getParent();
System.out.println("文件的上级目录为 : " + strParentDirectory);
}
}
以上代码运行输出结果为:
文件的上级目录为 : File
尊贵的董事大人
英文标题不为空时 视为本栏投稿
需要关键字 描述 英文标题