Example usage for java.io File mkdirs

List of usage examples for java.io File mkdirs

Introduction

In this page you can find the example usage for java.io File mkdirs.

Prototype

public boolean mkdirs() 

Source Link

Document

Creates the directory named by this abstract pathname, including any necessary but nonexistent parent directories.

Usage

From source file:com.athomas.androidkickstartr.util.ResourcesUtils.java

private static void copyResourcesToFromJar(File target, URL url) throws IOException {
    JarURLConnection connection = (JarURLConnection) url.openConnection();
    JarFile jarFile = connection.getJarFile();

    Enumeration<JarEntry> entries = jarFile.entries();

    while (entries.hasMoreElements()) {
        JarEntry jarEntry = entries.nextElement();
        InputStream is = jarFile.getInputStream(jarEntry);
        String entryPath = jarEntry.getName();

        File file = null;//from   www . j  a  v a 2s  .c o  m
        String dirs = "";
        if (entryPath.contains("/")) {
            int lastIndexOf = entryPath.lastIndexOf("/");
            dirs = (String) entryPath.subSequence(0, lastIndexOf + 1);
        }

        File parent = new File(target, dirs);
        parent.mkdirs();

        if (!jarEntry.isDirectory()) {
            String[] splitedPath = entryPath.split("/");
            String fileName = splitedPath[splitedPath.length - 1];
            file = new File(parent, fileName);
            FileUtils.copyInputStreamToFile(is, file);
        }
    }
}

From source file:com.cj.restspecs.mojo.Util.java

public static void mkdirs(File path) {
    if (!path.exists() && !path.mkdirs()) {
        throw new RuntimeException("Could not create directory: " + path.getAbsolutePath());
    }//from ww  w.j  a v a 2  s.com
}

From source file:Main.java

public static String SaveBitmap(Bitmap bmp, String name) {
    File file = new File("mnt/sdcard/picture/");
    String path = null;/*from w  w  w. jav  a 2  s.co  m*/
    if (!file.exists())
        file.mkdirs();
    try {
        path = file.getPath() + "/" + name;
        FileOutputStream fileOutputStream = new FileOutputStream(path);

        bmp.compress(Bitmap.CompressFormat.JPEG, 100, fileOutputStream);
        fileOutputStream.flush();
        fileOutputStream.close();
        System.out.println("saveBmp is here");
    } catch (Exception e) {
        e.printStackTrace();
    }

    return path;
}

From source file:Main.java

public static boolean saveBitmapToLocal(String path, String fileName, Bitmap b) {
    if (b == null) {
        return false;
    }/* w  w w  .j  ava2  s . c  o  m*/

    boolean result = false;
    String storageState = Environment.getExternalStorageState();
    if (storageState.equals(Environment.MEDIA_MOUNTED)) {

        File dir = new File(path);
        if (!dir.exists()) {
            dir.mkdirs();
        }
        FileOutputStream fos = null;

        try {
            fos = new FileOutputStream(path + fileName);
            b.compress(CompressFormat.JPEG, 100, fos);
            fos.flush();
            result = true;
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                fos.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

    }
    return result;
}

From source file:Main.java

private static String createDir(String path) {
    boolean isHaveSDCard = Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
    if (!isHaveSDCard) {
        return null;
    }/*from  w w w  . j  av a 2  s . c  om*/
    File directory = Environment.getExternalStorageDirectory();
    File file = new File(directory.getAbsolutePath() + path);
    if (!file.exists()) {
        boolean isSuccess = file.mkdirs();
        if (isSuccess) {
            return file.getPath() + File.separator;
        } else {
            return null;
        }
    }
    return file.getPath() + File.separator;
}

From source file:Main.java

public static boolean mkdir(String path) {
    File file = new File(path);
    if (file.isDirectory())
        return true;
    else {/*from  ww w  . ja  va  2s  .c om*/
        boolean creadok = file.mkdirs();
        if (creadok) {
            return true;
        } else {
            return false;
        }
    }
}

From source file:org.duracloud.mill.audit.generator.AuditLogGeneratorDriver.java

/**
 * @param logRootPath/*from w  w w  . j  a v  a 2s  . c o m*/
 */
private static void initializeLogRoot(String logRootPath) {

    try {
        File logRootDir = new File(logRootPath);

        if (!logRootDir.exists()) {
            if (!logRootDir.mkdirs()) {
                String message = "Unable to create log root dir: " + logRootDir.getAbsolutePath()
                        + ". Please make sure that this process has " + "permission to create this directory";
                log.error(message);
                System.exit(1);
            }
        }

        SystemConfig.instance().setLogsDirectory(logRootPath);
    } catch (Exception ex) {
        log.error("failed to initialize log root dir " + logRootPath + ":" + ex.getMessage(), ex);
        System.exit(1);
    }

}

From source file:asia.gkc.vneedu.utils.FileUtil.java

/**
 * /*from   ww  w . j  a  v a2s. c  o m*/
 *
 * @param dirs - 
 * @return 
 */
public static boolean buildDir(File dirs) {
    return dirs.exists() || dirs.mkdirs();
}

From source file:muffinc.yafdivj.helper.FeretHandler.java

public static void move(File file) {
    try {// w  w w .  java2 s.co m

        String newFolder = NEW_FOLDER + file.getName().substring(1, 5) + "/";
        File file1 = new File(newFolder);

        if (!file1.exists()) {
            file1.mkdirs();
        }

        Files.copy(file.toPath(), new File(newFolder + file.getName()).toPath());

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

From source file:Main.java

public static File getHomeFileLoc() {
    File sdcard = Environment.getExternalStorageDirectory();
    File sdpath = new File(sdcard.getAbsolutePath() + File.separator + "KnouNotice");
    if (!sdpath.exists()) {
        boolean flag = sdpath.mkdirs();
    }//from  w ww .j  a  va 2  s  .  co  m
    return sdpath;
}