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:com.netflix.imfutility.itunes.chapters.ChaptersXmlProviderTest.java

@BeforeClass
public static void setupAll() throws IOException {
    // create both working directory and logs folder.
    FileUtils.deleteDirectory(TemplateParameterContextCreator.getWorkingDir());
    File workingDir = TemplateParameterContextCreator.getWorkingDir();
    if (!workingDir.mkdir()) {
        throw new RuntimeException("Could not create a working dir within tmp folder");
    }/*from   w w  w .  ja  va2s. com*/
    //  set user.dir to working directory
    userDir = System.getProperty("user.dir");
    System.setProperty("user.dir", workingDir.getAbsolutePath());

    ChaptersUtils.createChapterFile(1);
    ChaptersUtils.createChapterFile(2);
}

From source file:alluxio.AlluxioTestDirectory.java

/**
 * Creates a directory with the given prefix inside the Alluxio temporary directory.
 *
 * @param prefix a prefix to use in naming the temporary directory
 * @return the created directory/*w ww . ja  va2s . c  o m*/
 */
public static File createTemporaryDirectory(String prefix) {
    final File file = new File(ALLUXIO_TEST_DIRECTORY, prefix + "-" + UUID.randomUUID());
    if (!file.mkdir()) {
        throw new RuntimeException("Failed to create directory " + file.getAbsolutePath());
    }

    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
        public void run() {
            try {
                alluxio.util.io.FileUtils.deletePathRecursively(file.getAbsolutePath());
            } catch (IOException e) {
                LOG.warn("Failed to clean up Alluxio test directory {} : {}", file.getAbsolutePath(),
                        e.getMessage());
            }
        }
    }));
    return file;
}

From source file:azkaban.storage.LocalStorage.java

private static File createIfDoesNotExist(String baseDirectoryPath) {
    final File baseDirectory = new File(baseDirectoryPath);
    if (!baseDirectory.exists()) {
        baseDirectory.mkdir();
        log.info("Creating dir: " + baseDirectory.getAbsolutePath());
    }/*from  w w w . j a  v a2 s  .co  m*/
    return baseDirectory;
}

From source file:Main.java

public static void writeLifeLogCountInFile(int walking, int running, int vehicle, int bicycle, String filename)
        throws IOException {
    Date date = new Date();
    BufferedWriter writer = null;
    File dir = new File(Environment.getExternalStorageDirectory() + "/LifeLog");
    Log.d("Directory PATH", dir.getAbsolutePath());
    boolean flag = dir.mkdir();
    Log.d("Directory created?", "" + flag);
    File file = new File(dir.getAbsolutePath(), filename);
    if (file.exists() == false) {
        file.createNewFile();/* w  w w  .jav a2  s.c  o m*/
        writer = new BufferedWriter(new FileWriter(file, true));
        writer.write("Date,Walking,Running,Bicycle,Vehicle");
        writer.newLine();
        writer.write(date.toString() + "," + walking + "," + running + "," + bicycle + "," + vehicle);
        writer.newLine();
    } else {
        writer = new BufferedWriter(new FileWriter(file, true));
        writer.write(date.toString() + "," + walking + "," + running + "," + bicycle + "," + vehicle);
        writer.newLine();
        Log.d("Appended", "True");
    }
    writer.flush();
    writer.close();

}

From source file:Main.java

public static void restoreDb(File currentDB, String restoreDBFileName) {
    try {//from   w  w  w .  java2  s .  c  o m
        backupDb(currentDB);
        File sd = Environment.getExternalStorageDirectory();
        File data = Environment.getDataDirectory();

        if (sd.canWrite()) {
            File f = new File(sd.getAbsolutePath() + "/AccountManagement");
            if (!f.exists()) {
                f.mkdir();
            }
            String restoreDBPath = "AccountManagement/" + restoreDBFileName;
            File restoreDB = new File(sd, restoreDBPath);

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

From source file:DBMS.UpdateFileUpload.java

public static boolean processFile(String path, FileItemStream item, int id) {
    try {//  w w w. ja  v  a2s. co  m
        String check = item.getName();
        if (check.endsWith(".jpg") || check.endsWith(".JPG")) {
            String imstring = "images/" + Integer.toString(id);
            File f = new File(path + File.separator + imstring);
            if (!f.exists())
                f.mkdir();
            File savedFile = new File(f.getAbsolutePath() + File.separator + item.getName());
            FileOutputStream fos = new FileOutputStream(savedFile);
            InputStream is = item.openStream();
            int x = 0;
            byte[] b = new byte[1024];
            while ((x = is.read(b)) != -1) {
                fos.write(b, 0, x);
            }
            fos.flush();
            fos.close();
            String dbimage = imstring + "/a.jpg";
            //dc.enterImage(dbimage);
            //im =dbimage;
            //System.out.println("Resizing!");
            //Resize rz = new Resize();
            //rz.resize(dbimage);
            BufferedImage originalImage = ImageIO.read(savedFile);
            int type = originalImage.getType() == 0 ? BufferedImage.TYPE_INT_ARGB : originalImage.getType();
            BufferedImage resizeImageJpg = resizeImage(originalImage, type);
            ImageIO.write(resizeImageJpg, "jpg", savedFile);
            File rFile = new File(f.getAbsolutePath() + "/a.jpg");
            savedFile.renameTo(rFile);
            ProfileEditDB dc = new ProfileEditDB();
            dc.enterImage(id, dbimage);
            System.out.println("Link Entered to Database!");
            return true;
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}

From source file:helpers.FileUpload.java

public static boolean processFile(String path, FileItemStream item) {
    try {/*from   www .jav  a  2  s  .c o  m*/

        File f = new File(path + File.separator + "assets" + File.separator + "uploads");
        if (!f.exists()) {
            f.mkdir();
        }
        File savedFile = new File(f.getAbsolutePath() + File.separator + item.getName());
        FileOutputStream fos = new FileOutputStream(savedFile);
        InputStream is = item.openStream();
        int x = 0;
        byte[] b = new byte[1024];
        while ((x = is.read(b)) != -1) {
            fos.write(b, 0, x);
        }
        fos.flush();
        fos.close();
        return true;
    } catch (Exception e) {
        System.out.println("FileUpload 35: " + e.getMessage());
    }
    return false;
}

From source file:net.rptools.tokentool.util.FileSaveUtil.java

public static boolean makeDir(String dirName, File destDir) {
    if (dirName.isEmpty())
        return false;

    File newDir;
    newDir = new File(destDir, dirName);
    if (newDir.mkdir()) {
        log.info("Created directory: " + newDir.getAbsolutePath());
        return true;
    } else {/*from ww w.  j  av a2  s .  c  o  m*/
        log.error("Could not create directory: " + newDir.getAbsolutePath());
    }

    return false;
}

From source file:Main.java

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, "amapsdk");
        boolean result = false;
        if (!autonaviDir.exists()) {
            result = autonaviDir.mkdir();
        }// www .  j av  a  2s.c  o m
        java.io.File minimapDir = new java.io.File(autonaviDir, "offlineMap");
        if (!minimapDir.exists()) {
            result = minimapDir.mkdir();
        }
        return minimapDir.toString() + "/";
    } else {
        return "";
    }
}

From source file:Main.java

public static void unzip(String strZipFile) {

    try {/*from   ww w  .  j a  va  2  s .  com*/
        /*
         * STEP 1 : Create directory with the name of the zip file
         * 
         * For e.g. if we are going to extract c:/demo.zip create c:/demo directory where we can extract all the zip entries
         */
        File fSourceZip = new File(strZipFile);
        String zipPath = strZipFile.substring(0, strZipFile.length() - 4);
        File temp = new File(zipPath);
        temp.mkdir();
        System.out.println(zipPath + " created");

        /*
         * STEP 2 : Extract entries while creating required sub-directories
         */
        ZipFile zipFile = new ZipFile(fSourceZip);
        Enumeration<? extends ZipEntry> e = zipFile.entries();

        while (e.hasMoreElements()) {
            ZipEntry entry = (ZipEntry) e.nextElement();
            File destinationFilePath = new File(zipPath, entry.getName());

            // create directories if required.
            destinationFilePath.getParentFile().mkdirs();

            // if the entry is directory, leave it. Otherwise extract it.
            if (entry.isDirectory()) {
                continue;
            } else {
                // System.out.println("Extracting " + destinationFilePath);

                /*
                 * Get the InputStream for current entry of the zip file using
                 * 
                 * InputStream getInputStream(Entry entry) method.
                 */
                BufferedInputStream bis = new BufferedInputStream(zipFile.getInputStream(entry));

                int b;
                byte buffer[] = new byte[1024];

                /*
                 * read the current entry from the zip file, extract it and write the extracted file.
                 */
                FileOutputStream fos = new FileOutputStream(destinationFilePath);
                BufferedOutputStream bos = new BufferedOutputStream(fos, 1024);

                while ((b = bis.read(buffer, 0, 1024)) != -1) {
                    bos.write(buffer, 0, b);
                }

                // flush the output stream and close it.
                bos.flush();
                bos.close();

                // close the input stream.
                bis.close();
            }

        }
        zipFile.close();
    } catch (IOException ioe) {
        System.out.println("IOError :" + ioe);
    }

}