Example usage for java.io File mkdir

List of usage examples for java.io File mkdir

Introduction

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

Prototype

public boolean mkdir() 

Source Link

Document

Creates the directory named by this abstract pathname.

Usage

From source file:Main.java

private static File getDirectoryBoards() {
    File file = new File(Environment.getExternalStorageDirectory(), DIR_BOARDS_EXTERNAL);
    if (!file.exists()) {
        file.mkdir();
    }//from  w w  w  .j  a v  a 2s .c o  m

    return file;
}

From source file:Main.java

public static String writeBitmap(byte[] data, int cameraDegree, Rect rect, Rect willTransformRect)
        throws IOException {
    File file = new File(Environment.getExternalStorageDirectory() + "/bookclip/");
    file.mkdir();
    String bitmapPath = file.getPath() + "/" + System.currentTimeMillis() + ".png";

    // bitmap rotation, scaling, crop
    BitmapFactory.Options option = new BitmapFactory.Options();
    option.inSampleSize = 2;/*w ww.ja  va  2  s  .c  om*/
    Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length, option);
    Matrix bitmapMatrix = new Matrix();
    bitmapMatrix.setRotate(cameraDegree);
    int x = rect.left, y = rect.top, width = rect.right - rect.left, height = rect.bottom - rect.top;
    Bitmap rotateBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), bitmapMatrix,
            false);
    // bitmap recycle
    bitmap.recycle();

    Bitmap scaledBitmap = Bitmap.createScaledBitmap(rotateBitmap, willTransformRect.right,
            willTransformRect.bottom - willTransformRect.top, false);
    // rotatebitmap recycle
    rotateBitmap.recycle();

    Bitmap cropBitmap = Bitmap.createBitmap(scaledBitmap, x, y, width, height, null, false);
    // scaledBitmap recycle
    scaledBitmap.recycle();

    // file write
    FileOutputStream fos = new FileOutputStream(new File(bitmapPath));
    cropBitmap.compress(CompressFormat.PNG, 100, fos);
    fos.flush();
    fos.close();

    // recycle
    cropBitmap.recycle();

    return bitmapPath;
}

From source file:Main.java

public static void unZip(String zipFile, String outputFolder) throws IOException {

    byte[] buffer = new byte[1024];

    //create output directory is not exists
    File folder = new File(outputFolder);
    if (!folder.exists()) {
        folder.mkdir();
    }/*from w  w w .  ja va2 s  . co  m*/

    //get the zip file content
    ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFile));
    //get the zipped file list entry
    ZipEntry ze = zis.getNextEntry();

    while (ze != null) {

        String fileName = ze.getName();
        File newFile = new File(outputFolder + File.separator + fileName);

        //create all non exists folders
        //else you will hit FileNotFoundException for compressed folder
        if (ze.isDirectory())
            newFile.mkdirs();
        else {
            newFile.getParentFile().mkdirs();

            FileOutputStream fos = new FileOutputStream(newFile);

            int len;
            while ((len = zis.read(buffer)) > 0) {
                fos.write(buffer, 0, len);
            }

            fos.close();
        }
        ze = zis.getNextEntry();
    }

    zis.closeEntry();
    zis.close();

}

From source file:com.thoughtworks.go.helpers.FileSystemUtils.java

public static File getTestRootDir() {
    File root = new File(ROOT);
    if (!root.exists() && !root.mkdir()) {
        throw new RuntimeException("Failed to create directory for test data [" + root.getAbsolutePath() + "]");
    }//from   w  ww  . ja  v a2s . com
    return root;
}

From source file:Main.java

public static File createTemporaryFile(String part, String ext) throws Exception {
    File tempDir = Environment.getExternalStorageDirectory();
    tempDir = new File(tempDir.getAbsolutePath() + "/.temp/");
    if (!tempDir.exists()) {
        tempDir.mkdir();
    }/*from w ww  .  ja  v a 2  s .co m*/
    return File.createTempFile(part, ext, tempDir);
}

From source file:Main.java

public static void unzipEPub(String inputZip, String destinationDirectory) throws IOException {
    int BUFFER = 2048;
    List zipFiles = new ArrayList();
    File sourceZipFile = new File(inputZip);
    File unzipDestinationDirectory = new File(destinationDirectory);
    unzipDestinationDirectory.mkdir();

    ZipFile zipFile;/*  w ww.  j av  a 2s .c  o  m*/
    zipFile = new ZipFile(sourceZipFile, ZipFile.OPEN_READ);
    Enumeration zipFileEntries = zipFile.entries();

    // Process each entry
    while (zipFileEntries.hasMoreElements()) {

        ZipEntry entry = (ZipEntry) zipFileEntries.nextElement();
        String currentEntry = entry.getName();
        File destFile = new File(unzipDestinationDirectory, currentEntry);

        if (currentEntry.endsWith(".zip")) {
            zipFiles.add(destFile.getAbsolutePath());
        }

        File destinationParent = destFile.getParentFile();
        destinationParent.mkdirs();

        if (!entry.isDirectory()) {
            BufferedInputStream is = new BufferedInputStream(zipFile.getInputStream(entry));
            int currentByte;
            // buffer for writing file
            byte data[] = new byte[BUFFER];

            FileOutputStream fos = new FileOutputStream(destFile);
            BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER);

            while ((currentByte = is.read(data, 0, BUFFER)) != -1) {
                dest.write(data, 0, currentByte);
            }
            dest.flush();
            dest.close();
            is.close();

        }

    }
    zipFile.close();

    for (Iterator iter = zipFiles.iterator(); iter.hasNext();) {
        String zipName = (String) iter.next();
        unzipEPub(zipName,
                destinationDirectory + File.separatorChar + zipName.substring(0, zipName.lastIndexOf(".zip")));
    }
}

From source file:Main.java

public static String getPicStorePath(Context ctx) {
    File file = ctx.getExternalFilesDir(null);
    if (file == null) {
        file = ctx.getFilesDir();// www  .  j a v  a2s  . com
    }
    if (!file.exists()) {
        file.mkdir();
    }
    File imageStoreFile = new File(file.getAbsolutePath() + "/mq");
    if (!imageStoreFile.exists()) {
        imageStoreFile.mkdir();
    }
    return imageStoreFile.getAbsolutePath();
}

From source file:com.cloudera.knittingboar.utils.DataUtils.java

public static synchronized File getTwentyNewsGroupDir() throws IOException {
    if (twentyNewsGroups != null) {
        return twentyNewsGroups;
    }/*from   ww w.ja  v a  2s. c om*/
    // mac gives unique tmp each run and we want to store this persist
    // this data across restarts
    File tmpDir = new File("/tmp");
    if (!tmpDir.isDirectory()) {
        tmpDir = new File(System.getProperty("java.io.tmpdir"));
    }
    File baseDir = new File(tmpDir, TWENTY_NEWS_GROUP_LOCAL_DIR);
    if (!(baseDir.isDirectory() || baseDir.mkdir())) {
        throw new IOException("Could not mkdir " + baseDir);
    }
    File tarFile = new File(baseDir, TWENTY_NEWS_GROUP_TAR_FILE_NAME);

    if (!tarFile.isFile()) {
        FileUtils.copyURLToFile(new URL(TWENTY_NEWS_GROUP_TAR_URL), tarFile);
    }

    Process p = Runtime.getRuntime()
            .exec(String.format("tar -C %s -xvf %s", baseDir.getAbsolutePath(), tarFile.getAbsolutePath()));
    BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
    System.out.println("Here is the standard error of the command (if any):\n");
    String s;
    while ((s = stdError.readLine()) != null) {
        System.out.println(s);
    }
    stdError.close();
    twentyNewsGroups = baseDir;
    return twentyNewsGroups;
}

From source file:TemplateImporter.java

public static void downloadInfo(String url) throws Exception {

    List<Map<String, String>> items = getThumbNails(url);

    //List<String> names = getThumbNails();

    //Iterator<Map<String, String>> iter = item

    for (Map<String, String> item : items) {

        String name = item.get("Name");

        System.out.println("-----------------");
        System.out.println(name);
        String thumbnail = "http://www.freecsstemplates.org/templates/thumbnails/" + name + ".gif";
        String template = "http://www.freecsstemplates.org/templates/previews/" + name + "/";
        String path = "/home/kureem/csstemplates/" + name;
        File dir = new File(path);
        dir.mkdir();

        addFile(thumbnail, path + "/" + name + ".gif");
        //byte[] abImages = IOUtil.getStreamContentAsBytes(new URL(thumbnail).openStream());
        //FileOutputStream fout = new FileOutputStream(new File(path + "/" + name + ".gif"));
        //fout.write(abImages);
        //fout.flush();
        //fout.close();

        addFile(template, path + "/" + name + ".html");

        Source src = new Source(new FileInputStream(path + "/" + name + ".html"));
        List<Element> links = src.getAllElements("link");
        List<StartTag> linkStartTags = src.getAllStartTags(HTMLElementName.LINK);
        for (StartTag link : linkStartTags) {
            String css = link.getAttributeValue("href");
            String cssUrl = "http://www.freecsstemplates.org/templates/previews/" + name + "/" + css;
            addFile(cssUrl, path + "/" + css);

            String scss = IOUtil.getFileContenntAsString(path + "/" + css);
            String[] asParts = StringUtils.splitByWholeSeparator(scss, "url(");
            for (String s : asParts) {
                if (s.startsWith("images/")) {
                    String aaap = StringUtils.split(s, ")")[0];

                    new File(path + "/images").mkdir();
                    try {
                        addFile(template + aaap, path + "/" + aaap);
                    } catch (Exception e) {
                        System.out.println(template + aaap);
                    }/*from  w  ww.  j  av  a2 s.c  om*/
                }
            }
        }

    }

}

From source file:Main.java

/**
 * extracts a zip file to the given dir//w ww . ja  v a  2 s.c  om
 * @param archive
 * @param destDir
 * @throws IOException 
 * @throws ZipException 
 * @throws Exception
 */
public static void extractZipArchive(File archive, File destDir) throws ZipException, IOException {
    if (!destDir.exists()) {
        destDir.mkdir();
    }

    ZipFile zipFile = new ZipFile(archive);
    Enumeration<? extends ZipEntry> entries = zipFile.entries();

    byte[] buffer = new byte[16384];
    int len;
    while (entries.hasMoreElements()) {
        ZipEntry entry = entries.nextElement();

        String entryFileName = entry.getName();

        File dir = buildDirectoryHierarchyFor(entryFileName, destDir);
        if (!dir.exists()) {
            dir.mkdirs();
        }

        if (!entry.isDirectory()) {
            BufferedOutputStream bos = new BufferedOutputStream(
                    new FileOutputStream(new File(destDir, entryFileName)));

            BufferedInputStream bis = new BufferedInputStream(zipFile.getInputStream(entry));

            while ((len = bis.read(buffer)) > 0) {
                bos.write(buffer, 0, len);
            }

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