Example usage for java.io File createNewFile

List of usage examples for java.io File createNewFile

Introduction

In this page you can find the example usage for java.io File createNewFile.

Prototype

public boolean createNewFile() throws IOException 

Source Link

Document

Atomically creates a new, empty file named by this abstract pathname if and only if a file with this name does not yet exist.

Usage

From source file:docs.AbstractGemFireIntegrationTests.java

protected static File writeProcessControlFile(File path) throws IOException {
    assertThat(path != null && path.isDirectory()).isTrue();

    File processControl = new File(path, DEFAULT_PROCESS_CONTROL_FILENAME);

    assertThat(processControl.createNewFile()).isTrue();

    processControl.deleteOnExit();//from w  w w. j a va 2s.co m

    return processControl;
}

From source file:com.avatarproject.core.storage.UserCache.java

private static void create(File file) {
    if (!file.getParentFile().exists()) {
        try {/*w  w w. ja va 2 s .c o  m*/
            file.getParentFile().mkdirs();
        } catch (Exception e) {
            AvatarProjectCore.get().getLogger().info("Failed to generate directory!");
            e.printStackTrace();
        }
    }

    if (!file.exists()) {
        try {
            file.createNewFile();
        } catch (Exception e) {
            AvatarProjectCore.get().getLogger().info("Failed to generate " + file.getName() + "!");
            e.printStackTrace();
        }
    }
}

From source file:com.ikanow.aleph2.data_model.utils.ProcessUtils.java

/**
 * Writes pid=date out to /app/aleph2/pid_manager/bucket._id/application_name
 * /*from  w w w.j  ava 2  s  . co m*/
 * @param application_name
 * @param bucket
 * @param aleph_root_path
 * @param pid
 * @param date
 * @throws IOException 
 */
private static void storePid(final String application_name, final DataBucketBean bucket,
        final String aleph_root_path, final String pid, final long date) throws IOException {
    final File file = new File(
            aleph_root_path + PID_MANAGER_DIR_NAME + bucket._id() + File.separator + application_name);
    file.getParentFile().mkdirs();
    if (file.exists())
        file.delete();
    file.createNewFile();
    final PrintWriter pw = new PrintWriter(file);
    pw.print(pid + "=" + date);
    pw.close();
}

From source file:ac.ucy.cs.spdx.license.License.java

/**
 * Saves the License passed as parameter in a text file inside the standard
 * directory./*from   ww  w  . jav a 2s .co  m*/
 * 
 * @param License
 */
public static void saveLicense(License l) {
    File text = new File("licensesText/" + l.getIdentifier() + ".txt");
    if (text.exists())
        return;
    FileWriter fw = null;
    BufferedWriter bw = null;
    try {
        text.createNewFile();
        fw = new FileWriter(text);
        bw = new BufferedWriter(fw);
        bw.write(l.getLicenseName() + "\n");
        bw.write(l.getIdentifier() + "\n");
        bw.write(l.getLicenseText());
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            bw.close();
            fw.close();
        } catch (IOException e) {
        }

    }

}

From source file:org.shareok.data.documentProcessor.DocumentProcessorUtil.java

public static void outputStringToFile(String loggingIngo, String filePath) {
    try {/*  www  .  j  a  v a  2 s.c  o m*/
        File file = new File(filePath);
        if (!file.exists()) {
            file.createNewFile();
        }
        FileOutputStream op = new FileOutputStream(file);
        byte[] loggingIngoBytes = loggingIngo.getBytes();
        op.write(loggingIngoBytes);
        op.flush();
        op.close();
    } catch (FileNotFoundException ex) {
        Logger.getLogger(DocumentProcessorUtil.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(DocumentProcessorUtil.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.microfocus.application.automation.tools.octane.executor.UFTTestDetectionService.java

private static void createInitialDetectionFile(FilePath workspace) {
    try {/*from   ww w  . j  av a 2s  . co  m*/
        File rootFile = new File(workspace.toURI());
        File file = new File(rootFile, INITIAL_DETECTION_FILE);
        logger.info("Initial detection file path : " + file.getPath());
        file.createNewFile();
    } catch (IOException | InterruptedException e) {
        logger.error("Failed to createInitialDetectionFile : " + e.getMessage());
    }
}

From source file:br.msf.maven.compressor.CompressorService.java

private static void writeContents(final CharSequence content, final File f, final Charset encoding)
        throws Exception {
    if (f == null) {
        return;/*from  w  w  w  .j  a  v  a 2s  .  c  o m*/
    }
    final byte[] bytes = content.toString().getBytes(encoding);
    OutputStream os = null;
    try {
        if (!f.exists()) {
            f.getParentFile().mkdirs(); // create path directories
            f.createNewFile(); // create empty file
        }
        os = new FileOutputStream(f);
        os.write(bytes);
        os.flush();
    } finally {
        IOUtils.closeQuietly(os);
    }
}

From source file:com.aliyun.odps.local.common.utils.DownloadUtils.java

public static File downloadTable(Odps odps, TableMeta tableMeta, PartitionSpec partition,
        int limitDownloadRecordCount, char inputColumnSeperator) {

    TableInfo tableInfo = TableInfo.builder().projectName(tableMeta.getProjName())
            .tableName(tableMeta.getTableName()).partSpec(partition).build();

    List<String[]> records = downloadTableData(odps, tableMeta.getProjName(), tableMeta.getTableName(),
            partition, limitDownloadRecordCount, null);

    File tableDir = WareHouse.getInstance().getTableDir(tableMeta.getProjName(), tableMeta.getTableName());
    if (!tableDir.exists()) {
        tableDir.mkdirs();/*from  www.  j a v a 2s .  c o m*/
    }

    File dataDir = tableDir;
    if (partition != null) {
        dataDir = new File(tableDir, PartitionUtils.toString(partition));
        if (!dataDir.exists()) {
            dataDir.mkdirs();
        }
    }

    LOG.info("Start to write table: " + tableInfo.toString() + "-->" + dataDir.getAbsolutePath());

    File dataFile = new File(dataDir, "data");
    try {
        dataFile.createNewFile();
    } catch (IOException e1) {
    }
    CsvWriter writer = new CsvWriter(dataFile.getAbsolutePath(), inputColumnSeperator, encoding);
    try {
        for (String[] record : records) {
            writer.writeRecord(record);
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    writer.close();

    LOG.info("Finished write table: " + tableInfo.toString() + "-->" + dataDir.getAbsolutePath());

    return dataDir;
}

From source file:net.amigocraft.mpt.command.InstallCommand.java

@SuppressWarnings("unchecked")
public static void downloadPackage(String id) throws MPTException {
    JSONObject packages = (JSONObject) Main.packageStore.get("packages");
    if (packages != null) {
        JSONObject pack = (JSONObject) packages.get(id);
        if (pack != null) {
            if (pack.containsKey("name") && pack.containsKey("version") && pack.containsKey("url")) {
                if (pack.containsKey("sha1") || !Config.ENFORCE_CHECKSUM) {
                    String name = pack.get("name").toString();
                    String version = pack.get("version").toString();
                    String fullName = name + " v" + version;
                    String url = pack.get("url").toString();
                    String sha1 = pack.containsKey("sha1") ? pack.get("sha1").toString() : "";
                    if (pack.containsKey("installed")) { //TODO: compare versions
                        throw new MPTException(ID_COLOR + name + ERROR_COLOR + " is already installed");
                    }/* w w w .j  a v  a 2 s.c  om*/
                    try {
                        URLConnection conn = new URL(url).openConnection();
                        conn.connect();
                        ReadableByteChannel rbc = Channels.newChannel(conn.getInputStream());
                        File file = new File(Main.plugin.getDataFolder(),
                                "cache" + File.separator + id + ".zip");
                        file.setReadable(true, false);
                        file.setWritable(true, false);
                        file.getParentFile().mkdirs();
                        file.createNewFile();
                        FileOutputStream os = new FileOutputStream(file);
                        os.getChannel().transferFrom(rbc, 0, MiscUtil.getFileSize(new URL(url)));
                        os.close();
                        if (!sha1.isEmpty() && !sha1(file.getAbsolutePath()).equals(sha1)) {
                            file.delete();
                            throw new MPTException(ERROR_COLOR + "Failed to install package " + ID_COLOR
                                    + fullName + ERROR_COLOR + ": checksum mismatch!");
                        }
                    } catch (IOException ex) {
                        throw new MPTException(
                                ERROR_COLOR + "Failed to download package " + ID_COLOR + fullName);
                    }
                } else
                    throw new MPTException(ERROR_COLOR + "Package " + ID_COLOR + id + ERROR_COLOR
                            + " is missing SHA-1 checksum! Aborting...");
            } else
                throw new MPTException(ERROR_COLOR + "Package " + ID_COLOR + id + ERROR_COLOR
                        + " is missing required elements!");
        } else
            throw new MPTException(ERROR_COLOR + "Cannot find package with id " + ID_COLOR + id);
    } else {
        throw new MPTException(ERROR_COLOR + "Package store is malformed!");
    }
}