文件夹的建立和文件的建立

public class Demo13 {

    /**
     * createNewFile()
     * 创建一个新的文件,前提是前面的文件都必须存在
     * @param args
     */
    public static void main(String[] args) {
        String path = "e:/e";
        File f = new File(path);
        if(!f.exists()){
            f.mkdirs();
        }
        // fileName表示你创建的文件名;为txt类型;
        String fileName="test.txt";
        File file = new File(f,fileName);
        if(!file.exists()){
            try {
                file.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

    /**
     * springmvc中的这个不需要预先建立文件夹一定是
     * 内部封装了。所以我们在建立的时候。为了同一记忆就是先建立文件加在进行
     * 文件的建立
     */
    //4.判断路径是否存在
    File file = new File(basePath+"/"+datePath);
    /*  if(!file.exists()) {
          file.mkdirs();
      }*/
//5.使用 MulitpartFile 接口中方法,把上传的文件写到指定位置
    File file1 = new File(file, fileName);
        uploadFile.transferTo(file1);
                return "success";
                }

猜你喜欢

转载自blog.csdn.net/qq_34627002/article/details/80867317
今日推荐