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

public static void mkdirs(File file) throws IOException {
    if (file.isDirectory()) {
        return;//from w w w . j  a v  a 2s. c o m
    }
    if (!file.mkdirs()) {
        if (file.exists()) {
            throw new IOException("failed to create " + file + " file exists and not a directory");
        }
        throw new IOException();
    }
}

From source file:com.bluexml.xforms.messages.DefaultMessages.java

/**
 * @param filePath/*from w w w  .j  a va2 s . c  o m*/
 * @param allLines
 * @return
 * @throws IOException
 */
private static boolean generate(String filePath, String[] allLines) throws IOException {
    String line;
    FileOutputStream fos = null;
    try {
        int pos = filePath.lastIndexOf(File.separator);
        String dirPath = filePath.substring(0, pos);
        File dir = new File(dirPath);
        dir.mkdirs();
        fos = new FileOutputStream(filePath);
        for (String property : allLines) {
            line = property + "\n";
            fos.write(line.getBytes());
        }
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    } finally {
        if (fos != null) {
            fos.close();
        }
    }
    return true;
}

From source file:net.sourceforge.atunes.utils.ZipUtils.java

/**
 * Utility method to create directory structure
 * /*from  w  w  w . j a  va  2  s. co  m*/
 * @param dir
 */
private static void createDir(File dir) throws IOException {
    if (!dir.mkdirs()) {
        throw new IOException("Can not create dir " + dir);
    }
}

From source file:Main.java

private static boolean checkFsWritable(String dir) {

    if (dir == null)
        return false;

    File directory = new File(dir);

    if (!directory.isDirectory()) {
        if (!directory.mkdirs()) {
            return false;
        }/*  w  w  w  . j  a  v  a 2s  . co m*/
    }

    File f = new File(directory, ".keysharetestgzc");
    try {
        if (f.exists()) {
            f.delete();
        }
        if (!f.createNewFile()) {
            return false;
        }
        f.delete();
        return true;

    } catch (Exception e) {
    }
    return false;

}

From source file:Main.java

public static void saveBitmapToFile(Bitmap bitmap, String _file) throws IOException {
    BufferedOutputStream os = null;
    try {//from  w  w  w  .  j  a  v a 2  s. co  m
        File file = new File(_file);
        // String _filePath_file.replace(File.separatorChar +
        // file.getName(), "");
        int end = _file.lastIndexOf(File.separator);
        String _filePath = _file.substring(0, end);
        File filePath = new File(_filePath);
        if (!filePath.exists()) {
            filePath.mkdirs();
        }
        file.createNewFile();
        os = new BufferedOutputStream(new FileOutputStream(file));
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, os);
    } finally {
        if (os != null) {
            try {
                os.close();
            } catch (IOException e) {
                Log.e("TAG_ERROR", e.getMessage(), e);
            }
        }
    }
}

From source file:Main.java

public static void copyCompletely(URI input, URI output) throws IOException {
    try {//from   www .  jav  a2  s  .  c  o m
        InputStream in = null;
        try {
            File f = new File(input);
            if (f.exists())
                in = new FileInputStream(f);
        } catch (Exception notAFile) {
        }

        File out = new File(output);
        File dir = out.getParentFile();
        dir.mkdirs();

        if (in == null)
            in = input.toURL().openStream();

        copyCompletely(in, new FileOutputStream(out));
    } catch (IllegalArgumentException e) {
        throw new IOException("Cannot copy to " + output);
    }
}

From source file:Main.java

private static void initData(Activity activity) {
    mActivity = activity;//from  w ww .java 2  s .c  o  m
    File mFile = new File(Environment.getExternalStorageDirectory() + "/jiayuan");
    if (!mFile.exists())
        mFile.mkdirs();
    mAvatar = new File(TEMP_IMG_PATH);
    if (mAvatar.exists())
        mAvatar.delete();
    mAvatarUri = Uri.fromFile(mAvatar);
}

From source file:Main.java

public static void copyFiles(String sourcePath, String targetPath) throws IOException {
    File srcDir = new File(sourcePath);
    File[] files = srcDir.listFiles();
    FileChannel in = null;/* ww w  .j av  a 2 s .com*/
    FileChannel out = null;
    for (File file : files) {
        try {
            in = new FileInputStream(file).getChannel();
            File outDir = new File(targetPath);
            if (!outDir.exists()) {
                outDir.mkdirs();
            }
            File outFile = new File(targetPath + File.separator + file.getName());
            out = new FileOutputStream(outFile).getChannel();
            in.transferTo(0, in.size(), out);
        } finally {
            if (in != null)
                in.close();
            if (out != null)
                out.close();
        }
    }
}

From source file:com.adaptris.core.stubs.TempFileUtils.java

public static File createTrackedDir(String prefix, String suffix, File baseDir, Object tracker)
        throws IOException {
    File f = File.createTempFile(prefix, suffix, baseDir);
    f.delete();//from   w w w.j  a v a  2s . c  om
    f.mkdirs();
    cleaner.track(f, tracker, FileDeleteStrategy.FORCE);
    return trackFile(f, tracker);
}

From source file:io.trivium.anystore.StoreUtils.java

public static void createIfNotExists(String url) {
    Logger logger = Logger.getLogger(StoreUtils.class.getName());
    File m = new File(url);
    if (!m.exists()) {
        m.mkdirs();
        logger.log(Level.FINE, "creating directory {}", url);
    }//from  ww w  .j a  v  a 2  s  .  co m
}