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 String getSDKServerFolder(Context ctx) {
    if (ctx == null) {
        return null;
    }//from  ww w.  jav  a 2s .c  o  m
    String packageName = ctx.getPackageName();
    if (packageName == null || packageName.length() <= 0) {
        return null;
    }
    File serverFolder = new File("/data/data/" + packageName + "/ECSDK_Msg");
    if (!serverFolder.exists() && !serverFolder.mkdirs()) {
        return null;
    }
    return serverFolder.getAbsolutePath();
}

From source file:Main.java

public static boolean saveToSDCard(Bitmap bitmap) {
    if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        return false;
    }/*from  w  ww.  j  a v  a  2s.  c  o m*/
    FileOutputStream fileOutputStream = null;
    File file = new File("/sdcard/myName/Download/");
    if (!file.exists()) {
        file.mkdirs();
    }
    String fileName = UUID.randomUUID().toString() + ".jpg";
    String filePath = "/sdcard/myName/Download/" + fileName;
    File f = new File(filePath);
    if (!f.exists()) {
        try {
            f.createNewFile();
            fileOutputStream = new FileOutputStream(filePath);
            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fileOutputStream);
        } catch (IOException e) {
            return false;
        } finally {
            try {
                fileOutputStream.flush();
                fileOutputStream.close();
            } catch (IOException e) {
                return false;
            }
        }
    }
    return true;
}

From source file:Main.java

public static void saveBitmap(String dirpath, String filename, Bitmap bitmap, boolean isDelete) {
    File dir = new File(dirpath);
    if (!dir.exists()) {
        dir.mkdirs();
    }/*  www  . ja  va 2  s.co m*/

    File file = new File(dirpath, filename);
    if (isDelete) {
        if (file.exists()) {
            file.delete();
        }
    }

    if (!file.exists()) {
        try {
            file.createNewFile();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    FileOutputStream out = null;
    try {
        out = new FileOutputStream(file);
        if (bitmap.compress(Bitmap.CompressFormat.PNG, 100, out)) {
            out.flush();
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (out != null) {
            try {
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:Main.java

public static void copyDir(String src, String dst) {
    try {/* www . j  av a  2  s .c  o m*/
        File fileSrc = new File(src);
        if (!fileSrc.exists()) {
            return;
        }
        File[] filelist = fileSrc.listFiles();
        File fileDst = new File(dst);
        if (!fileDst.exists()) {
            fileDst.mkdirs();
        }
        for (File f : filelist) {
            if (f.isDirectory()) {
                copyDir(f.getPath() + "/", dst + f.getName() + "/");
            } else {
                copyFile(f.getPath(), dst + f.getName());
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.twitter.heron.downloader.Extractor.java

static void extract(InputStream in, Path destination) throws IOException {
    try (final BufferedInputStream bufferedInputStream = new BufferedInputStream(in);
            final GzipCompressorInputStream gzipInputStream = new GzipCompressorInputStream(
                    bufferedInputStream);
            final TarArchiveInputStream tarInputStream = new TarArchiveInputStream(gzipInputStream)) {
        final String destinationAbsolutePath = destination.toFile().getAbsolutePath();

        TarArchiveEntry entry;// w w  w  .j a v  a 2  s.c  o  m
        while ((entry = (TarArchiveEntry) tarInputStream.getNextEntry()) != null) {
            if (entry.isDirectory()) {
                File f = Paths.get(destinationAbsolutePath, entry.getName()).toFile();
                f.mkdirs();
            } else {
                Path fileDestinationPath = Paths.get(destinationAbsolutePath, entry.getName());

                Files.copy(tarInputStream, fileDestinationPath, StandardCopyOption.REPLACE_EXISTING);
            }
        }
    }
}

From source file:Main.java

public static Uri getOutputUri() {
    File dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
    if (dir.exists() == false) {
        dir.mkdirs();
    }//from   w w  w .  j a  va 2  s  .c  o  m
    File file = new File(dir, "photo.png");
    return Uri.fromFile(file);
}

From source file:Main.java

static public String prepareFilePath(String fileName, String dir) throws IOException {
    File dictionaryRoot = new File(Environment.getExternalStorageDirectory(), dir);
    File dictionaryDirFile = new File(dictionaryRoot, fileName.substring(0, 1));
    if (!dictionaryDirFile.exists()) {
        if (!dictionaryDirFile.mkdirs()) {
            throw new IOException("Cannot create directory: " + dictionaryDirFile);
        }/*  w  w  w .  j a v  a 2  s .  c  om*/
    }
    return new File(dictionaryDirFile, fileName + ".mp3").getCanonicalPath();
}

From source file:Main.java

public static void makeRootDirectory(String filePath) {
    File file = null;
    try {// www. j a v  a2 s. c  om
        file = new File(filePath);
        if (!file.exists()) {
            file.mkdirs();
        }
    } catch (Exception e) {

    }
}

From source file:Main.java

public static String getImagePathInExternalStoragePublicDirectory(String filename) {

    File path = Environment.getExternalStoragePublicDirectory("uDrove");
    File file = new File(path, filename + ".jpg");
    path.mkdirs();

    if (file.exists()) {

        return file.getPath();
    }//from w  w  w. ja va 2s  . co  m

    return "";
}

From source file:com.google.gdt.eclipse.designer.hosted.tdt.GWTEnvironmentUtils.java

/**
 * @return the path for GWT cache.//from w w w  . ja va  2 s .c  o  m
 */
public static File getCacheDirectory() {
    String path = "C:/Work/GWT/.dev-cache";
    // attempt to use separate cache location for different GWT test suites, which we run in parallel
    {
        String suffix = System.getProperty("wbp.testing.gwtCacheSuffix");
        if (suffix != null) {
            path += "/" + suffix;
        } else {
            path += "/Main";
        }
    }
    // done
    {
        File file = new File(path);
        file.mkdirs();
        return file;
    }
}