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.cjwagner.InfoSecPriv.ExtensionServer.java

private static void initializeLogStore() {

    System.out.println("Date: " + new Date().getTime());
    System.out.println("Initializing Log Store...");

    int fileLoadCount = 0;
    storeSize = 0;/*from   w  ww  . ja  v  a  2  s. c  om*/
    logStore = new ConcurrentHashMap<String, LoggerMessage>();
    File dir = new File(logDir);
    dir.mkdir();

    File[] files = dir.listFiles();
    for (File file : files) {
        String fullName = file.getName();
        String ext = getExtension(fullName);
        String ip = rmvExtension(fullName);
        if (!ext.equals(logFileExt) || ip.length() == 0) {
            continue;
        }
        LoggerMessage data = null;
        try {
            System.out.println(file.toString());
            String json = FileUtils.readFileToString(file, null);
            data = LoggerMessage.fromJSON(json);
        } catch (Exception e) {
            System.out.println("Failed to parse file: " + fullName + "  ERROR: " + e.getMessage());
            continue;
        }
        //data is verified at this point
        LoggerMessage rec = logStore.get(ip);
        if (rec == null) {
            logStore.put(ip, data);
        } else {
            rec.getLogs().addAll(data.getLogs());
        }
        storeSize += data.getLogs().size();
        fileLoadCount++;
    }
    System.out.println(
            "Initialization complete.  Files loaded: " + fileLoadCount + "  Total logs loaded: " + storeSize);
}

From source file:Main.java

/**
 * The directory of video storage used when the user wants the videos to
 * be automatically picked up by the media scanner (and visible in the
 * Gallery)./*from w  w w .  j  a  va 2  s . c  om*/
 */
public static File getVideosPublicDir() {
    File dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES);
    if (!dir.exists()) {
        dir.mkdir();
    }
    return dir;
}

From source file:ee.ria.DigiDoc.configuration.Configuration.java

private static void createDirectory(File dir) {
    if (!dir.exists()) {
        boolean mkdir = dir.mkdir();
        if (mkdir) {
            Timber.d("initLibraryConfiguration: created %s directory", dir.getName());
        }//from   ww  w.j a va2s. co  m
    }
}

From source file:Main.java

public static File getExtWorkingDir(Context context) {
    if (!isExternalStorageWritable())
        return null;
    File workingDir = new File(Environment.getExternalStorageDirectory() + File.separator + "data");
    if (!workingDir.exists())
        workingDir.mkdir();
    workingDir = new File(workingDir + File.separator + getPackageName(context));
    if (!workingDir.exists())
        workingDir.mkdir();//  w ww.java 2s .c  o m
    return workingDir;
}

From source file:Main.java

public static File getTempFile(Context context) {
    //It will return /sdcard/image.tmp
    final File path = new File(Environment.getExternalStorageDirectory(), context.getPackageName());
    if (!path.exists()) {
        path.mkdir();
    }/*w w  w .  j a v a2s . c o m*/
    return new File(path, "image.tmp");
}

From source file:Main.java

/**
 * Get the application download folder on the SD Card. Create it if not present.
 * @return The application download folder.
 *//* ww  w. j  a  va 2 s  . co m*/
public static File getDownloadFolder() {
    File root = getApplicationFolder();

    if (root != null) {

        File folder = new File(root, DOWNLOAD_FOLDER);

        if (!folder.exists()) {
            folder.mkdir();
        }

        return folder;

    } else {
        return null;
    }
}

From source file:Main.java

public static void unZip(InputStream zipFileIS, String outputFolder) throws IOException {

    byte[] buffer = new byte[1024];

    //create output directory is not exists
    File folder = new File(outputFolder);
    if (!folder.exists()) {
        folder.mkdir();
    }//from   w  w  w  .j  av a2 s. co m

    //get the zip file content
    ZipInputStream zis = new ZipInputStream(zipFileIS);
    //get the zipped file list entry
    ZipEntry ze = zis.getNextEntry();

    while (ze != null) {

        String fileName = ze.getName();
        File newFile = new File(outputFolder + File.separator + fileName);

        if (ze.isDirectory()) {
            newFile.mkdirs();
        } else {

            FileOutputStream fos = new FileOutputStream(newFile);

            int len;
            while ((len = zis.read(buffer)) > 0) {
                fos.write(buffer, 0, len);
            }

            fos.flush();
            fos.close();
        }
        ze = zis.getNextEntry();
    }

    zis.closeEntry();
    zis.close();
}

From source file:com.hp.test.framework.Reporting.cleanTempDir.java

public static void cleanandCreate(String Reports_path, int last_run) {

    String temp_path = Reports_path + "\\temp";

    deleteDir(new File(temp_path));
    File file = new File(temp_path);
    boolean isDirectoryCreated = file.mkdir();
    if (isDirectoryCreated) {
        log.info("successfully Created directory");
    } else {//from   w w  w . j  a  va  2  s.  c  o  m
        file.delete();
        file.mkdir();
        log.info("deleted and Created directory");
    }

    File trgDir = new File(temp_path);

    File srcDir = new File(Reports_path);

    try {
        FileUtils.copyDirectory(srcDir, trgDir);
        log.info("Copying reports to temp path is completed");
    } catch (IOException ex) {
        log.error("Issue with the copying reports to temp directory" + ex.getMessage());
    }
    try {
        removerunlinks.removelinksforpreRuns(temp_path + "\\results\\", "ConsolidatedPage.html", last_run);
    } catch (IOException ex) {
        log.error("Error in removing links from the page ConsolidatedPage.html" + ex.getMessage());
    }
    for (int i = 1; i < last_run; i++) {
        try {
            deleteDir(new File(temp_path + "\\results\\Run_" + i));
        } catch (Exception ex) {
            log.error("Not able to delete directory" + temp_path + "\\results\\Run_" + i);
        }
        log.error("Deleted" + temp_path + "\\results\\Run_" + i);
    }
    FileUtils.deleteQuietly(new File(temp_path + "\\ISTF_Reports.zip"));
    // ZipUtils.ZipFolder(temp_path, Reports_path+);

}

From source file:Main.java

/**
 * DB test//from  w w w  .  ja  v  a  2 s . c  om
 */
public static void runBackup(Context context) {
    File file = context.getDatabasePath("PhotoDeskHiddenFolder.db");
    int size = (int) file.length();

    String path = Environment.getExternalStorageDirectory() + "/PhotoDesk/";
    try {
        byte[] buffer = new byte[size];
        InputStream inputStream = new FileInputStream(file);
        inputStream.read(buffer);
        inputStream.close();

        File outputDBDirectory = new File(path);
        if (!outputDBDirectory.isDirectory())
            outputDBDirectory.mkdir();

        path += "test.db";

        File outputFile = new File(path);
        FileOutputStream outputStream = new FileOutputStream(outputFile);
        outputStream.write(buffer);
        outputStream.flush();
        outputStream.close();

    } catch (Exception e) {
    }
}

From source file:Main.java

public static File getDiskDir(String uniqueName) {
    if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
            || !Environment.isExternalStorageRemovable()) {
        File storageDirectory = Environment.getExternalStorageDirectory();
        if (storageDirectory != null) {
            File file = new File(storageDirectory + File.separator + uniqueName);
            if (!file.exists() && !file.isDirectory()) {
                file.mkdir();
            }//from   ww w.  j a v  a  2  s .c o m
            return file;
        }
    }
    return null;
}