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 boolean makeDirs(String filePath) {
    String folderName = getFolderName(filePath);
    if (TextUtils.isEmpty(folderName)) {
        return false;
    }/*from  ww w .j  a  v a 2 s .  c o  m*/

    File folder = new File(folderName);
    return (folder.exists() && folder.isDirectory()) || folder.mkdirs();
}

From source file:Main.java

public static void saveFile(String tPath, String name, String text) {
    try {/*from  ww  w.java 2s .c  o m*/
        File file = new File(tPath);
        file.mkdirs();
        FileWriter fw = new FileWriter(tPath + name, false);
        fw.write(text);
        fw.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void makeRootDirectory(String filePath) {
    File file = null;
    try {/*  ww w . ja  va 2  s . c om*/
        file = new File(filePath);
        if (!file.exists()) {
            file.mkdirs();
        }
    } catch (Exception e) {
        Log.i("error:", e + "");
    }
}

From source file:Main.java

public static File createDefaultCacheDir(Context context) {
    File cache = new File(context.getApplicationContext().getCacheDir(), PICASSO_CACHE);
    if (!cache.exists()) {
        cache.mkdirs();
    }/*from   w  w w . jav a2  s .  co m*/
    return cache;
}

From source file:Main.java

public static void writeUrlToFile(String urlToRead, String folderToWrite, String fileName)
        throws MalformedURLException, IOException {
    URL urlIn = new URL(urlToRead);
    File folderOut = new File(folderToWrite);
    if (!(folderOut.exists() || folderOut.mkdirs())) {
        throw new RuntimeException("could not create folder " + folderToWrite);
    }//from w w  w  . j a  v a 2s . c  o  m
    File fileOut = new File(folderOut, fileName);
    try (InputStream in = new BufferedInputStream(urlIn.openStream());
            OutputStream out = new BufferedOutputStream(new FileOutputStream(fileOut));) {
        transfer(in, out);
    }
}

From source file:Main.java

public static boolean isDir(String path) {
    File fPath = new File(path);
    if (fPath == null) {
        return false;
    }//w  w  w.  ja va 2s. c  om
    return fPath.isDirectory() || fPath.mkdirs();
}

From source file:Main.java

public static File createDir(String dirPath) {
    File dirFile = new File(dirPath);
    if (!dirFile.exists() || !dirFile.isDirectory()) {
        boolean success = dirFile.mkdirs();
        if (!success) {
            return null;
        }/*from   w w  w .  j  ava 2s  .c o  m*/
    }

    return dirFile;
}

From source file:Main.java

public static Boolean writeToSDFile(String directory, String file_name, String text) {

    // Find the root of the external storage.
    // See//from   ww w.j  av a2  s.  c om
    // http://developer.android.com/guide/topics/data/data-storage.html#filesExternal

    File root = Environment.getExternalStorageDirectory();

    // See
    // http://stackoverflow.com/questions/3551821/android-write-to-sd-card-folder

    File dir = new File(root.getAbsolutePath() + "/" + directory);
    dir.mkdirs();
    File file = new File(dir, file_name);

    try {
        FileOutputStream f = new FileOutputStream(file);
        PrintWriter pw = new PrintWriter(f);
        pw.println(text);
        pw.flush();
        pw.close();
        f.close();
        // Log.v(TAG, "file written to sd card");
        return true;
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        // Log.i(TAG, "******* File not found. Did you" +
        // " add a WRITE_EXTERNAL_STORAGE permission to the manifest?");
        return false;
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    }
}

From source file:br.edu.ifpb.utils.PhotoUtils.java

public static String salvarFoto(String nomePasta, String nomeFoto, InputStream foto) {
    BufferedImage bf = null;//  ww w .j ava2 s  . c om
    String path = nomePasta;

    try {
        bf = ImageIO.read(foto);
        path = path.replaceAll("%20", " ");
        File file = new File(path);
        if (!file.exists()) {
            file.mkdirs();
        }
        file = new File(path + nomeFoto);
        FileOutputStream fos = new FileOutputStream(file);
        fos.write(getByteImage(bf));

        //            return path.substring(path.indexOf("img/")) + nomeFoto;
        return path + nomeFoto;
    } catch (IOException ex) {
        throw new CouldNotCreateFileException("O arquivo " + (path + nomeFoto) + " no pde ser criado.");
    }
}

From source file:brooklyn.entity.cloudfoundry.LocalResourcesDownloader.java

public static String createLocalPathName(String fileName) {
    String targetDirName = LocalResourcesDownloader.findATmpDir();
    String filePathName = targetDirName + File.separator + fileName;

    File targetDir = new File(targetDirName);
    targetDir.mkdirs();

    return filePathName;
}