java - 创建文件

  

package practice;

import java.io.File;
import java.io.IOException;

public class CreateFile {

    public static void main(String[] args) {
        
        File f = new File("src/practice","hello.txt");
        
        
        if(!f.exists()) {
            try {
                f.createNewFile();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            
            System.out.println("创建成功");
        }else {
            System.out.println("文件已存在");
        }
        
    }
    
}

 

posted @ 2020-10-19 10:15  武卡卡  阅读(114)  评论(0编辑  收藏  举报