s-day08--File中的创建功能
This commit is contained in:
@@ -0,0 +1,27 @@
|
|||||||
|
package com.inmind.file01;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/*
|
||||||
|
6.File中的创建功能
|
||||||
|
public boolean createNewFile() :当且仅当具有该名称的文件尚不存在时,创建一个新的空文件。(重点)
|
||||||
|
public boolean mkdir() :创建由此File表示的目录。
|
||||||
|
public boolean mkdirs() :创建由此File表示的目录,包括任何必需但不存在的父目录。(重点)
|
||||||
|
*/
|
||||||
|
public class Demo05 {
|
||||||
|
public static void main(String[] args) throws IOException {
|
||||||
|
//public boolean createNewFile() :当且仅当具有该名称的文件尚不存在时,创建一个新的空文件。(重点)
|
||||||
|
// File file = new File("a.txt");
|
||||||
|
// File file = new File("a");
|
||||||
|
File file = new File("c\\c.txt");
|
||||||
|
if (!file.exists()) {
|
||||||
|
//如果文件不存在则直接创建
|
||||||
|
// file.createNewFile();
|
||||||
|
// file.mkdir();
|
||||||
|
file.mkdirs();
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("程序结束");
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user