现在的位置: 首页 > 综合 > 正文

java 创建文件夹和文件

2013年04月19日 ⁄ 综合 ⁄ 共 717字 ⁄ 字号 评论关闭

import java.io.*;

 

public class Fan {

        public static void main(String[] args) {
  
        String path ="d://upload_test//file";          //设置一个默认文件夹路径
        File uploadFilePath = new File(path);

        // 如果该目录不存在,则创建之
        if(uploadFilePath.exists() == false) {
               uploadFilePath.mkdirs();
               System.out.println("路径不存在,但是已经成功创建了" + path);
        }else{
              System.out.println("文件路径存在" + path);
        }
       
        String filePath = path+"//xin.txt";
        File createFile = new File(filePath);
        try {
                 createFile.createNewFile();
                 System.out.println("文件创建成功!");
        } catch (IOException e) {
                System.out.println("文件创建失败了!");
                e.printStackTrace();
       }

   }

}

抱歉!评论已关闭.