Java中Io类-File类的构造方法

package com.hxzy.IOSer;
import java.io.*;
public class Demo02 {

public static void main(String[] args) {
//Gu_1();
// Gu_2("gubin");
Gu_3();



}
/*
* 第三种
*File(File parent, String child)
*两个参数 第一个父路径参数是一个File 类型的对象 第二个子路径参数是String 类型的子路径
* 好处: 第一个参数是File类型的参数 这个参数可以在下面调用File类的方法 更加灵活
*
* */
public static void Gu_3() {
File parent = new File("D:");
File file = new File(parent,"eclipse");
System.out.println(file);
}
/* 第二种
* 创建File 类的的构造方法
* File(File parent, String child)
* 传递两个参数 传递 两个参数 第一个参数是 父目录 第二个是子目录
* 比如 "C:","eclipse"
* 这个构造方法的好处是 灵活性比较高
* 方法可以写参数
* aa("eclisps");
* public static void aa(String sp){
* File file = new File("C:",sp);
* }
* */

public static void Gu_2 (String sp) {
File file = new File("C:",sp);
System.out.println(file);
}

/* 第一种
* 创建file 类的构造方法
* 构造方法的参数 写 一个相对路径 注意 路径名称不区分大小写
* 比如 c://Eclipse 或者 c:eclipse 都是可以的
* */
public static void Gu_1() {
File file = new File("c://eclipse");

System.out.println(file);
}


}

原文地址:https://www.cnblogs.com/gu-bin/p/10034294.html