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:Main.java

private static synchronized File getTempDirectory(Context context) {
    File tempDir = new File(context.getFilesDir(), "temps/");
    if (!tempDir.exists()) {
        tempDir.mkdirs();
    }/*w  w w  .  j ava  2s . c  o m*/
    return tempDir;
}

From source file:Main.java

public static int upZipFile(File zipFile, String folderPath) throws IOException {
    ZipFile zfile = new ZipFile(zipFile);
    Enumeration zList = zfile.entries();
    ZipEntry ze = null;/*from  ww w  . ja  v a  2  s . com*/
    byte[] buf = new byte[1024];
    while (zList.hasMoreElements()) {
        ze = (ZipEntry) zList.nextElement();
        if (ze.isDirectory()) {
            String dirstr = folderPath + ze.getName();
            dirstr = new String(dirstr.getBytes("8859_1"), "GB2312");
            File f = new File(dirstr);
            f.mkdirs();
            continue;
        }
        OutputStream os = new BufferedOutputStream(
                new FileOutputStream(getRealFileName(folderPath, ze.getName())));
        InputStream is = new BufferedInputStream(zfile.getInputStream(ze));
        int readLen = 0;
        while ((readLen = is.read(buf, 0, 1024)) != -1) {
            os.write(buf, 0, readLen);
        }
        is.close();
        os.close();
    }
    zfile.close();
    return 0;
}

From source file:Main.java

public static boolean createFile(File file, boolean recursion) throws IOException {
    boolean result = false;
    if (!file.exists()) {
        try {//  w  w  w .j  ava  2 s . co  m
            result = file.createNewFile();
        } catch (IOException e) {
            if (!recursion) {
                throw e;
            }
            File parent = file.getParentFile();
            if (!parent.exists())
                parent.mkdirs();
            try {
                result = file.createNewFile();
            } catch (IOException e1) {
                throw e1;
            }
        }
    }
    return result;
}

From source file:Main.java

/**
 * Return a {@link File} pointing to the storage location for map tiles.
 *//* ww w.j  a  v  a2 s. c  o  m*/
public static File getTileFile(Context context, String filename) {
    File folder = new File(context.getFilesDir(), TILE_PATH);
    if (!folder.exists()) {
        folder.mkdirs();
    }
    return new File(folder, filename);
}

From source file:Main.java

public static void createDipPath(String file) {
    String parentFile = file.substring(0, file.lastIndexOf("/"));
    File file1 = new File(file);
    File parent = new File(parentFile);
    if (!file1.exists()) {
        parent.mkdirs();
        try {/*from w w w .  jav a  2  s  .  co m*/
            file1.createNewFile();
        } catch (IOException e) {
        }
    }
}

From source file:Main.java

public static void unZip(String path) {
    int count = -1;
    int index = -1;

    String savepath = "";

    savepath = path.substring(0, path.lastIndexOf("."));
    try {//ww  w.  ja va  2 s  . c o  m
        BufferedOutputStream bos = null;
        ZipEntry entry = null;
        FileInputStream fis = new FileInputStream(path);
        ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis));

        while ((entry = zis.getNextEntry()) != null) {
            byte data[] = new byte[buffer];

            String temp = entry.getName();
            index = temp.lastIndexOf("/");
            if (index > -1)
                temp = temp.substring(index + 1);
            String tempDir = savepath + "/zip/";
            File dir = new File(tempDir);
            dir.mkdirs();
            temp = tempDir + temp;
            File f = new File(temp);
            f.createNewFile();

            FileOutputStream fos = new FileOutputStream(f);
            bos = new BufferedOutputStream(fos, buffer);

            while ((count = zis.read(data, 0, buffer)) != -1) {
                bos.write(data, 0, count);
            }

            bos.flush();
            bos.close();
        }

        zis.close();

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

From source file:com.rover12421.shaka.lib.JarUtil.java

public static void getResourceAsFile(String resourcePath, String desPath) throws IOException {
    File parentFile = new File(desPath).getParentFile();
    if (!parentFile.exists()) {
        parentFile.mkdirs();
    }//from   www  .  j  a v  a2 s  . com
    try (InputStream in = Class.class.getResourceAsStream(resourcePath);
            FileOutputStream fos = new FileOutputStream(desPath)) {
        IOUtils.copy(in, fos);
    }
}

From source file:Main.java

public static boolean createDirectoryIfNecessary(String sdFolderName) {
    File dir = new File(Environment.getExternalStorageDirectory().getPath() + "/" + sdFolderName + "/");
    return !dir.exists() && dir.mkdirs();
}

From source file:Main.java

private static File createMediaFile(Context context, String parentPath) {
    String state = Environment.getExternalStorageState();
    File rootDir = state.equals(Environment.MEDIA_MOUNTED) ? Environment.getExternalStorageDirectory()
            : context.getCacheDir();//from w ww.j  a v  a 2 s  . co m

    File folderDir = new File(rootDir.getAbsolutePath() + parentPath);
    if (!folderDir.exists() && folderDir.mkdirs()) {

    }

    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.CHINA).format(new Date());
    String fileName = APP_NAME + "_" + timeStamp + "";
    File tmpFile = new File(folderDir, fileName + POSTFIX);
    return tmpFile;
}

From source file:Main.java

static public boolean copyAllAssertToCacheFolder(Context c) throws IOException {

    String[] files = c.getAssets().list("Devices");
    String filefolder = c.getFilesDir().toString();
    File devicefile = new File(filefolder + "/Devices/");
    devicefile.mkdirs();

    for (int i = 0; i < files.length; i++) {
        File devfile = new File(filefolder + "/Devices/" + files[i]);
        if (!devfile.exists()) {
            copyFileTo(c, "Devices/" + files[i], filefolder + "/Devices/" + files[i]);
        }/*from   w ww.ja va  2  s. c o m*/
    }
    String[] filestr = devicefile.list();
    for (int i = 0; i < filestr.length; i++) {
        Log.i("file", filestr[i]);
    }

    return true;
}