文件对象

package com.cskaoyan.IO.practice1;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;

/**创建文件对象,并创建该对象目录下的一个新的文件对象
* @author guojiageng
* @since 2022/07/06 09:10
*/

public class Demo1 {
public static void main(String[] args) throws FileNotFoundException {
File file = new File("D:\\Java\\demo\\JavaSE网站练习");
System.out.println("file的绝对路径:"+file.getAbsolutePath());
File sonFile = new File(file, "sonFile.txt");
// 实际只是产生了对象,但并没有产生真实文件
System.out.println("sonFile的绝对路径:"+sonFile.getAbsolutePath());
File f = new File("a.txt");
FileOutputStream inputStream = new FileOutputStream("a.txt");
// 使用输出流才会真正创建文件,而不单单只是创建对象
}
}
posted @ 2022-07-07 12:51  别怕庚哥来了  阅读(57)  评论(0)    收藏  举报