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:org.cloudfoundry.tools.io.local.LocalFolder.java

/**
 * Create a temporary folder./*from   w  w w  . j a va  2  s.  co m*/
 * @param prefix the folder prefix
 * @param suffix the folder suffix
 * @return a new temporary folder
 */
public static LocalFolder createTempFolder(String prefix, String suffix) {
    LocalFolder tempFolder;
    try {
        File tempFile = File.createTempFile(prefix, suffix);
        tempFile.delete();
        tempFile.mkdir();
        tempFolder = new LocalFolder(tempFile);
        tempFolder.createIfMissing();
        return tempFolder;
    } catch (IOException e) {
        throw new ResourceException(e);
    }
}

From source file:Main.java

private static String saveCroppedImage(Bitmap bmp) {
    File file = new File("/sdcard/myFolder");
    UUID uuid = UUID.randomUUID();
    String uid = uuid.toString();
    if (!file.exists())
        file.mkdir();
    String name = "/sdcard/" + uid + ".jpg";
    file = new File(name.trim());
    String fileName = file.getName();
    String mName = fileName.substring(0, fileName.lastIndexOf("."));
    String sName = fileName.substring(fileName.lastIndexOf("."));

    // /sdcard/myFolder/temp_cropped.jpg
    String newFilePath = "/sdcard/myFolder" + "/" + mName + "_cropped" + sName;
    file = new File(newFilePath);
    try {//from  w ww . j  a v a2s  .c  om
        file.createNewFile();
        FileOutputStream fos = new FileOutputStream(file);
        bmp.compress(Bitmap.CompressFormat.JPEG, 50, fos);
        fos.flush();
        fos.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return newFilePath;
}

From source file:Main.java

/**
 * Returns individual application cache directory (for only image caching from ImageLoader). Cache directory will be
 * created on SD card <i>("/Android/data/[app_package_name]/cache/uil-images")</i> if card is mounted. Else -
 * Android defines cache directory on device's file system.
 * //from  w  ww .  j a va 2 s .  c  o m
 * @param context Application context
 * @return Cache {@link File directory}
 */
public static File getIndividualCacheDirectory(Context context) {
    File cacheDir = getCacheDirectory(context);
    File individualCacheDir = new File(cacheDir, INDIVIDUAL_DIR_NAME);
    if (!individualCacheDir.exists()) {
        if (!individualCacheDir.mkdir()) {
            individualCacheDir = cacheDir;
        }
    }
    return individualCacheDir;
}

From source file:Main.java

public static void backupDb(File currentDB) {
    try {//from ww w.j a  v  a2  s. c om

        File sd = Environment.getExternalStorageDirectory();
        File data = Environment.getDataDirectory();

        if (sd.canWrite()) {
            File f = new File(sd.getAbsolutePath() + "/AccountManagement");
            if (!f.exists()) {
                f.mkdir();
            }
            Date currentDate = new Date();
            String currentDateStr = newFormat1.format(currentDate);

            currentDateStr = currentDateStr.trim();
            System.out.println(
                    "---------------------------------------------------------------" + currentDateStr);
            String backupDBPath = "AccountManagement/backup_" + currentDateStr + ".db";
            File backupDB = new File(sd, backupDBPath);

            if (currentDB.exists()) {
                FileChannel src = new FileInputStream(currentDB).getChannel();
                FileChannel dst = new FileOutputStream(backupDB).getChannel();
                dst.transferFrom(src, 0, src.size());
                src.close();
                dst.close();
            }
        }
    } catch (Exception e) {
        System.out.println(e);
    }
}

From source file:gov.nih.nci.cabig.caaers.utils.CaaersSerializerUtil.java

/**
 * This method writes given content to a xml file. Location of the file is $CATALINA_HOME/logs/serializedfiles/
 * @param serializedContent/*from   ww  w. j  a  va 2s.  com*/
 */
public static void dumpContentToFile(String content) {
    BufferedWriter out = null;
    StringBuilder sb = null;
    try {
        if (StringUtils.isEmpty(CATALINA_HOME)) {
            sb = new StringBuilder(USER_HOME);
        } else {
            sb = new StringBuilder(System.getenv("CATALINA_HOME"));
            sb.append("/logs");
        }
        sb.append("/serializedfiles");
        File file = new File(sb.toString());
        if (!file.isDirectory()) {
            file.mkdir();
        }
        sb.append("/session_").append(System.currentTimeMillis()).append(".xml");
        out = new BufferedWriter(new FileWriter(sb.toString()));
        out.write(content);
    } catch (Exception e) {
        logger.error("Exception while writing contect to file -- ", e);
    } finally {
        try {
            out.close();
        } catch (Exception e) {
        }
    }
}

From source file:com.zurich.lifeac.intra.control.FTPUtil.java

public static boolean downloadSingleFile(FTPClient ftpClient, String remoteFilePath, String savePath)
        throws IOException {

    // code to download a file...
    File downloadFile = new File(savePath);

    File parentDir = downloadFile.getParentFile();
    if (!parentDir.exists()) {
        parentDir.mkdir();
    }//from w w w.  j  a va  2s  .  co  m

    OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(downloadFile));
    try {
        ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
        System.out.println("downloadSingle FileremoteFilePath:" + remoteFilePath);
        return ftpClient.retrieveFile(remoteFilePath, outputStream);
    } catch (IOException ex) {
        throw ex;
    } finally {
        if (outputStream != null) {
            outputStream.close();
        }
    }
}

From source file:io.vertx.config.vault.utils.VaultDownloader.java

private static void unzip(File zipFilePath, File destDir) throws IOException {
    if (!destDir.exists()) {
        destDir.mkdir();
    }/*  w w w.  j  av  a  2  s .  co  m*/
    ZipInputStream zipIn = new ZipInputStream(new FileInputStream(zipFilePath));
    ZipEntry entry = zipIn.getNextEntry();
    // iterates over entries in the zip file
    while (entry != null) {
        String filePath = destDir.getAbsolutePath() + File.separator + entry.getName();
        if (!entry.isDirectory()) {
            // if the entry is a file, extracts it
            extractFile(zipIn, filePath);
        } else {
            // if the entry is a directory, make the directory
            File dir = new File(filePath);
            dir.mkdir();
        }
        zipIn.closeEntry();
        entry = zipIn.getNextEntry();
    }
    zipIn.close();
}

From source file:Main.java

/**
 * Get SDCard cache dir.//from  w  w  w. j a v a2s.  c  om
 *
 * @param context
 * @return
 */
public static String getSdCacheDir(Context context) {
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        java.io.File fExternalStorageDirectory = Environment.getExternalStorageDirectory();
        java.io.File autonaviDir = new java.io.File(fExternalStorageDirectory, "move");
        boolean result = false;
        if (!autonaviDir.exists()) {
            result = autonaviDir.mkdir();
        }
        java.io.File minimapDir = new java.io.File(autonaviDir, "offlineMap");
        if (!minimapDir.exists()) {
            result = minimapDir.mkdir();
        }
        return minimapDir.toString() + File.separator;
    } else {
        return "";
    }
}

From source file:com.hybris.mobile.logging.ExceptionHandler.java

private static String[] searchForStackTraces() {
    if (stackTraceFileList != null) {
        return stackTraceFileList;
    }//ww w  .j  a v a 2 s  .c  o m
    File dir = new File(RA.FILES_PATH + "/");
    dir.mkdir();
    FilenameFilter filter = new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.endsWith(".stacktrace");
        }
    };
    return (stackTraceFileList = dir.list(filter));
}

From source file:edu.clemson.cs.nestbed.common.util.ZipUtils.java

public static File unzip(byte[] zipData, File directory) throws IOException {
    ByteArrayInputStream bais = new ByteArrayInputStream(zipData);
    ZipInputStream zis = new ZipInputStream(bais);
    ZipEntry entry = zis.getNextEntry();
    File root = null;//w w w .  j  a va 2  s  .c  om

    while (entry != null) {
        if (entry.isDirectory()) {
            File f = new File(directory, entry.getName());
            f.mkdir();

            if (root == null) {
                root = f;
            }
        } else {
            BufferedOutputStream out;
            out = new BufferedOutputStream(new FileOutputStream(new File(directory, entry.toString())),
                    BUFFER_SIZE);

            // ZipInputStream can only give us one byte at a time...
            for (int data = zis.read(); data != -1; data = zis.read()) {
                out.write(data);
            }
            out.close();
        }

        zis.closeEntry();
        entry = zis.getNextEntry();
    }
    zis.close();

    return root;
}