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:eu.ggnet.dwoss.util.TempUtil.java

private static File tryPath(File path, String subPath) {
    if (path.isDirectory() && path.canWrite()) {
        File outputPath = new File(path, subPath);
        if (!outputPath.exists()) {
            if (!outputPath.mkdirs()) {
                return null;
            }/*from  www. ja  va2 s .com*/
        } else if (!(outputPath.isDirectory() && outputPath.canWrite())) {
            return null;
        }
        return outputPath;
    }
    return null;
}

From source file:Main.java

private static void file(String path) {
    File destDir = new File(path);
    Log.d(TAG, destDir.getAbsolutePath());
    if (!destDir.exists()) {
        Log.d(TAG, "false");
        destDir.mkdirs();
    }//  w w w  . j  a  v  a  2  s.c  om
}

From source file:Main.java

public static boolean writeFile(byte[] buffer, String folder, String fileName) {
    boolean writeSucc = false;
    boolean sdCardExist = Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
    String folderPath = "";
    if (sdCardExist) {
        folderPath = Environment.getExternalStorageDirectory() + File.separator + folder + File.separator;
    } else {// w  w  w.  java 2 s .c o  m
        writeSucc = false;
    }

    File fileDir = new File((folderPath));
    if (!fileDir.exists()) {
        fileDir.mkdirs();
    }

    File file = new File(folderPath + fileName);
    FileOutputStream out = null;

    try {
        out = new FileOutputStream(file);
        out.write(buffer);
        writeSucc = true;
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return writeSucc;
}

From source file:Main.java

/**
 * Create an default file for save image from camera.
 *
 * @return/*from  ww w . j a  v a2s .  c  o m*/
 * @throws IOException
 */
public static File createDefaultImageFile() throws IOException {
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(new Date());
    String imageFileName = "JPEG_" + timeStamp + ".jpg";
    File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
    if (!storageDir.exists()) {
        storageDir.mkdirs();
    }
    return new File(storageDir, imageFileName);
}

From source file:aiai.ai.station.StationResourceUtils.java

public static AssetFile prepareResourceFile(File rootDir, Enums.BinaryDataType binaryDataType, String id,
        String resourceFilename) {

    final AssetFile assetFile = new AssetFile();
    final File trgDir = new File(rootDir, binaryDataType.toString());
    if (!trgDir.exists() && !trgDir.mkdirs()) {
        assetFile.isError = true;//from  w  w  w .  j  a  va  2  s.  co  m
        log.error("Can't create resource dir for task: {}", trgDir.getAbsolutePath());
        return assetFile;
    }
    if (StringUtils.isNotBlank(resourceFilename)) {
        assetFile.file = new File(trgDir, resourceFilename);
    } else {
        final String resId = id.replace(':', '_');
        assetFile.file = new File(trgDir, "" + resId);
    }
    assetFile.isExist = assetFile.file.exists();

    if (assetFile.isExist) {
        if (assetFile.file.length() == 0) {
            assetFile.file.delete();
            assetFile.isExist = false;
        } else {
            assetFile.isContent = true;
        }
    }
    return assetFile;
}

From source file:com.googlecode.download.maven.plugin.internal.cache.DownloadCache.java

private static void createIfNeeded(final File basedir) {
    if (!basedir.exists()) {
        basedir.mkdirs();
    } else if (!basedir.isDirectory()) {
        throw new IllegalArgumentException(
                String.format("Cannot use %s as cache directory: file is already exist", basedir));
    }/*from w  w w.  j a v a2 s  .  co  m*/
}

From source file:Main.java

public static boolean createDirIfNotExisted(String path, boolean isNomedia) {
    File file = new File(path);
    File fileName = new File(path + "/.nomedia");
    try {//from ww w .  java2s.  c om
        if (!file.exists()) {
            file.mkdirs();
        }
        if (isNomedia && !fileName.exists()) {
            fileName.createNewFile();
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return true;
}

From source file:Main.java

/**
 * From original Android Camera App//  w w w .ja v  a  2s .  c om
 * See: http://android.git.kernel.org/?p=platform/packages/apps/Camera.git;a=blob;f=src/com/android/camera/ImageManager.java;h=76a6d1dffdcfb91f2c55032ce14f7cd9ecf7962c;hb=HEAD
 * @param imageData
 * @param quality
 * @param filename
 * @return
 */
public static boolean StoreByteImage(byte[] imageData, int quality, String filename) {
    String directory = storageTarget + "/FreqCap";
    Bitmap source = BitmapFactory.decodeByteArray(imageData, 0, imageData.length);

    OutputStream outputStream = null;
    String filePath = directory + "/" + filename;
    try {
        File dir = new File(directory);
        if (!dir.exists())
            dir.mkdirs();
        File file = new File(directory, filename);
        outputStream = new FileOutputStream(file);
        if (source != null) {
            source.compress(CompressFormat.JPEG, picCompression, outputStream);
        } else {
            outputStream.write(imageData);
            // degree[0] = getExifOrientation(filePath);
        }
        //         outputStream.flush();
        //         outputStream.close();
        Log.e(TAG, file.getAbsolutePath());
    } catch (FileNotFoundException ex) {
        Log.w(TAG, ex);
        return false;
    } catch (IOException ex) {
        Log.w(TAG, ex);
        return false;
    } finally {
        closeSilently(outputStream);
    }
    return true;
}

From source file:Main.java

public static File getCacheSubDirectory(Context context, String cacheSubDir) {
    File appCacheSubDir = new File(getCacheDirectory(context), cacheSubDir);

    if (!appCacheSubDir.exists())
        appCacheSubDir.mkdirs();

    return appCacheSubDir;
}

From source file:Main.java

/**
 * author: liuxu//ww w.j  av  a2s. com
 * save  bitmap into file
 * @param bitmap the bitmap
 * @param path full path of the file
 * @param quality  Hint to the compressor, 0-100. 0 meaning compress for
 *                 small size, 100 meaning compress for max quality. Some
 *                 formats, like PNG which is lossless, will ignore the
 *                 quality setting
 * @return true if success
 */
public static boolean saveBitmap(Bitmap bitmap, String path, int quality) {
    if (bitmap == null) {
        return false;
    }
    File file = new File(path);
    File parent = file.getParentFile();
    if (parent != null && !parent.exists()) {
        if (!parent.mkdirs()) {
            //Log.e(TAG, "saveBitmap, mkdir for parent fail");
            return false;
        }
    }
    try {
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));
        bitmap.compress(Bitmap.CompressFormat.JPEG, quality, bos);
        bos.flush();
        bos.close();
    } catch (IOException e) {
        //Log.d(TAG, "saveBitmap fail", e);
        return false;
    }
    return true;
}