File类的三种构造方法

 1 package cn.zmh.File;
 2 
 3 import java.io.File;
 4 /*
 5 *
 6 * File类的构造方法   三种重载形式
 7 *
 8 * */
 9 public class FileDemo1 {
10     public static void main(String[] args) {
11         fun2();
12     }
13     //3 传递  父路径   子字符串路径
14     // 好处  父路径   File类型  父路径就可以直接调用File类的方法   *****
15     public static void fun(){
16         File parent = new File("d:");
17         File file = new File(parent,"\java");
18         System.out.println(file);
19     }
20     // 2 传递字符串  父路径    字符串  子路径
21     public static void fun1(){
22         File file = new File("d:\day031");
23         System.out.println(file);
24     }
25     // 1  传递路径名
26     public static void fun2(){
27         File file = new File("d:","\java");
28         System.out.println(file);
29     }
30 }
原文地址:https://www.cnblogs.com/zhangmenghui/p/10586326.html