save File by creating new file and its parent folders - Java File Path IO

Java examples for File Path IO:Directory Create

Description

save File by creating new file and its parent folders

Demo Code


//package com.java2s;

import java.io.File;

public class Main {

    public static void saveFile(String destFilePathStr, String destFileName) {
        try {/*  ww w . j  a v  a 2  s . c om*/
            File destFilePath = new File(destFilePathStr);
            if (!destFilePath.exists()) {
                destFilePath.mkdirs();
                destFilePath = null;
            }
            File destFile = new File(destFilePathStr + "//" + destFileName);
            if (!destFile.exists()) {
                destFile.createNewFile();
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Related Tutorials