Create a new file, if the file exists, delete and create again.

@param targetFile file.

@return True: success, or false: failure.
434910
public static boolean createNewFile(File targetFile) {
        if (targetFile.exists()) delFileOrFolder(targetFile);
        try {
            return targetFile.createNewFile();
        } catch (IOException e) {
            return false;
        }
    }
279293
public static boolean execute(
    final File source, final File destination, boolean renameEmptyFiles) {
    if (renameEmptyFiles || (source.length() > 0)) {
      return source.renameTo(destination);
    }

    return source.delete();
  }
479712
public static boolean createFile(String filePath) {
        if (!StringUtils.isEmpty(filePath)) {
            File file = new File(filePath);
            return createFile(file);
        }
        return false;
    }
910306
private void renameFile(File source, File target) {
        if (!source.exists()) {
            // don't do anything if the source file doesn't exist
            return;
        }
        if (target.exists()) {
            target.delete();
        }
        boolean rc = source.renameTo(target);
        if (!rc) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, getFileName() + ": Unable to rename " + source + " to " + target);
            }
        }
    }
240639
def copy_file_if_update_required(source_file, target_file):
    
    if file_needs_update(target_file, source_file):
        shutil.copy(source_file, target_file)
704148
public boolean createNewFile() throws IOException
  {
    synchronized (LOCK) {
      if (! exists()) {
        clearStatusCache();
        WriteStreamOld s = openWrite();
        s.close();
        return true;
      }
    }

    return false;
  }
954307
public static void write(Image image, File targetFile) throws IORuntimeException {
		ImageOutputStream out = null;
		try {
			out = getImageOutputStream(targetFile);
			write(image, FileUtil.extName(targetFile), out);
		} finally {
			IoUtil.close(out);
		}
	}
579640
private OutputStream createSummaryStream(File targetFile) throws IOException {
        if (targetFile == null)
            return null;

        TextFileOutputStreamFactory factory = FFDCConfigurator.getFileOutputStreamFactory();
        OutputStream newStream = null;

        // Creation and rolling of files should be done as the server
        Object token = ThreadIdentityManager.runAsServer();
        try {
            newStream = factory.createOutputStream(targetFile);
        } finally {
            ThreadIdentityManager.reset(token);
        }

        return newStream;
    }
744968
public static void copyResourceFile(String source, Path target) throws IOException {
        InputStream resource = FsCrawlerUtil.class.getResourceAsStream(source);
        FileUtils.copyInputStreamToFile(resource, target.toFile());
    }
907775
public static void saveCertificate(X509Certificate cert, File targetFile) {
        File folder = targetFile.getAbsoluteFile().getParentFile();
        if (!folder.exists()) {
            folder.mkdirs();
        }
        File tmpFile = new File(folder, Long.toHexString(System.currentTimeMillis()) + ".tmp");
        try {
            boolean asPem = targetFile.getName().toLowerCase().endsWith(".pem");
            if (asPem) {
                // PEM encoded X509
                PEMWriter pemWriter = null;
                try {
                    pemWriter = new PEMWriter(new FileWriter(tmpFile));
                    pemWriter.writeObject(cert);
                    pemWriter.flush();
                } finally {
                    if (pemWriter != null) {
                        pemWriter.close();
                    }
                }
            } else {
                // DER encoded X509
                FileOutputStream fos = null;
                try {
                    fos = new FileOutputStream(tmpFile);
                    fos.write(cert.getEncoded());
                    fos.flush();
                } finally {
                    if (fos != null) {
                        fos.close();
                    }
                }
            }

            // rename tmp file to target
            if (targetFile.exists()) {
                targetFile.delete();
            }
            tmpFile.renameTo(targetFile);
        } catch (Exception e) {
            if (tmpFile.exists()) {
                tmpFile.delete();
            }
            throw new RuntimeException("Failed to save certificate " + cert.getSubjectX500Principal().getName(), e);
        }
    }
1303813
public static void updateFileFromFile(final File sourceFile, final String destinationFilePath) throws
        UpdateException {
        if (!sourceFile.exists()) {
            throw new UpdateException("Source file does not exist: " + sourceFile);
        }
        if (!sourceFile.isFile()) {
            throw new UpdateException("Not a file: " + sourceFile);
        }
        if (sourceFile.length() < 1) {
            throw new UpdateException("Source file is empty: " + sourceFile);
        }

        try {
            updateFileFromInputStream(new FileInputStream(sourceFile), destinationFilePath);
        } catch (IOException e) {
            throw new UpdateException("Unable to update file: " + e.getMessage(), e);
        }
    }
167847
private boolean deleteFile(String filename) throws Exception {
        if (filename == null) {
            return false;
        }
        File file = new File(storeDir, filename);
        return Files.deleteIfExists(file.toPath());
    }
1040524
public static void copyDirectory(File source, File target) {
        if (source.isDirectory()) {
            if (!target.exists()) {
                target.mkdir();
            }
            for (String child : source.list()) {
                copyDirectory(new File(source, child), new File(target, child));
            }
        } else {
            try {
                write(new FileInputStream(source), new FileOutputStream(target));
            } catch (IOException e) {
                if (target.isDirectory()) {
                    if (!target.exists()) {
                        if (!target.mkdirs()) {
                            throw E.ioException("cannot copy [%s] to [%s]", source, target);
                        }
                    }
                    target = new File(target, source.getName());
                } else {
                    File targetFolder = target.getParentFile();
                    if (!targetFolder.exists()) {
                        if (!targetFolder.mkdirs()) {
                            throw E.ioException("cannot copy [%s] to [%s]", source, target);
                        }
                    }
                }
                try {
                    write(new FileInputStream(source), new FileOutputStream(target));
                } catch (IOException e0) {
                    throw E.ioException(e0);
                }
            }
        }
    }
697306
public boolean createNewFile(Path f) throws IOException {
    if (exists(f)) {
      return false;
    } else {
      create(f, false, getDefaultBufferSize()).close();
      return true;
    }
  }
106221
private function _createTargetDir()
    {
        if (!$this->_targetDir) {
            return false;
        }
        $targetDir = rtrim($this->_targetDir, '/');
        if (!file_exists($targetDir)) {
            if (!@mkdir($targetDir, 0777, true)) {
                return false;
            }
        }
        return true;
    }
800162
function(targetPath, callback) {
            client
                .deleteFile(targetPath)
                .then(function() {
                    __executeCallbackAsync(callback, [null]);
                })
                .catch(callback);
        }
750267
@Override
    public boolean fileCreated(File file) throws WatchingException {
        try {
            createApplicationBundle();
        } catch (Exception e) {
            throw new WatchingException(e.getMessage(), file, e);
        }
        return true;
    }