集册 Java实例教程 创建新的空文件

创建新的空文件

欢马劈雪     最近更新时间:2020-01-02 10:19:05

523
创建新的空文件


import java.io.*;

 

public class Main {
/**
 * NowJava.com - 时代Java 提 供 
**/

 

  public static void main(String[] args) {

     File file = new File("C://demo.txt");

     boolean blnCreated = false;

     try

     {

       blnCreated = file.createNewFile();

     }

     catch(IOException ioe)

     {

       System.out.println("Error while creating a new empty file :" + ioe);

     }

   

     System.out.println("Was file " + file.getPath() + " created ? : " + blnCreated);

  }

}
/**
n o w j a v a . c o m - 时代Java
**/