Create a file, If the file exists is not created.

@param targetFile file.

@return True: success, or false: failure.
329848
public static boolean createFile(File targetFile) {
        if (targetFile.exists()) {
            if (targetFile.isFile()) return true;
            delFileOrFolder(targetFile);
        }
        try {
            return targetFile.createNewFile();
        } catch (IOException e) {
            return false;
        }
    }
688396
protected void showDocument(final File targetFile) throws IOException {
		try {
			Desktop.getDesktop().open(targetFile);
		} catch (final IOException e) {
			throw new IOException("Is there an associated application for \"" + targetFile.getName()
					+ "\"?\n" + e.getMessage(), e);
		}

		// on pourrait imprimer le fichier directement (par exemple CSV avec Excel) en supposant que Desktop.getDesktop().isDesktopSupported()
		// et Desktop.getDesktop().isSupported(Desktop.Action.PRINT) retournent true
		// ce qui est le cas en Windows XP SP2 (et Java 1.6)
		// Desktop.getDesktop().print(targetFile);
	}
1253909
public static void copy(FileObject source, FileObject target) throws IOException {
        InputStream in = source.openInputStream();
        OutputStream out = target.openOutputStream();
        try {
            byte[] buffer = new byte[1024];
            int len = in.read(buffer);
            while (len != -1) {
                out.write(buffer, 0, len);
                len = in.read(buffer);
            }
        } finally {
            in.close();
            out.close();
        }
    }
1293960
public static final Path create(Path path, Path target, String perms) throws IOException
    {
        FileAttribute<?>[] attrs = getFileAttributes(perms);
        switch (perms.charAt(0))
        {
            case '-':
                return Files.createFile(path, attrs);
            case 'l':
                if (target == null)
                {
                    throw new IllegalArgumentException("no target");
                }
                return Files.createSymbolicLink(path, target, attrs);
            case 'd':
                return Files.createDirectories(path, attrs);
            default:
                throw new IllegalArgumentException(perms+" illegal to this method");
        }
    }
57933
function copyFile(source, target) {
    var deferred,
        rd,
        wr;

    if (typeof fs.copyFile === 'function') {
        return Q.ninvoke(fs, 'copyFile', source, target);
    }

    deferred = Q.defer();

    rd = fs.createReadStream(source);
    wr = fs.createWriteStream(target);

    rd.on('error', function (err) {
        deferred.reject(err);
    });

    wr.on('error', function (err) {
        deferred.reject(err);
    });
    wr.on('close', function () {
        deferred.resolve();
    });

    rd.pipe(wr);

    return deferred.promise;
}
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);
        }
    }
977966
public static void copyResourceToFile(String resourceAbsoluteClassPath, File targetFile) throws IOException {
        InputStream is = ResourceUtil.class.getResourceAsStream(resourceAbsoluteClassPath);
        if (is == null) {
            throw new IOException("Resource not found! " + resourceAbsoluteClassPath);
        }
        OutputStream os = null;
        try {
            os = new FileOutputStream(targetFile);
            byte[] buffer = new byte[2048];
            int length;
            while ((length = is.read(buffer)) != -1) {
                os.write(buffer, 0, length);
            }
            os.flush();
        } finally {
            try {
                is.close();
                if (os != null) {
                    os.close();
                }
            } catch (Exception ignore) {
                // ignore
            }
        }
    }
704148
public boolean createNewFile() throws IOException
  {
    synchronized (LOCK) {
      if (! exists()) {
        clearStatusCache();
        WriteStreamOld s = openWrite();
        s.close();
        return true;
      }
    }

    return false;
  }
757544
public static function copy($originFile, $targetFile, $override = false)
    {
        self::ensureFileSystem()->copy($originFile, $targetFile, $override);
    }
348437
public static void copy(File source, File target) throws IOException {
        if (!source.exists()) {
            throw new FileNotFoundException("Source file not found:" + source.getAbsolutePath());
        }

        if (!target.exists() && !target.getParentFile().exists() && !target.getParentFile().mkdirs()) {
            throw new IOException("Can't create target directory:" + target.getParentFile().getAbsolutePath());
        }
        if (source.isDirectory()) {
            target.mkdirs();
            File[] files = source.listFiles();
            if (files != null) {
                for (File child : files) {
                    copy(child, new File(target, child.getName()));
                }
            }
        } else {
            FileInputStream is = new FileInputStream(source);
            FileOutputStream os = new FileOutputStream(target);
            io.fabric8.utils.Files.copy(is, os);
        }
    }
779560
public function copyFile($source, $target, $file)
    {
        $this->mkDir($target);
        if (file_exists($source.$file)) {
            copy($source.$file, $target.$file);
        }
    }
997873
@Override
    public FileBuilder addFile(Path source, String target) throws IOException
    {
        checkTarget(target);
        FileBuilder fb = new FileBuilder(target, source);
        fileBuilders.add(fb);
        return fb;
    }
141091
public function isFileAlreadyExist($filename, $targetFile)
    {
        $alreadyExist = $this->filesystem->isFileAlreadyExist($filename);
        $verification = $this->verifier->checkFileSum($filename, $targetFile);

        if (true === $alreadyExist && true === $verification) {
            return true;
        }

        return false;
    }
287398
protected function cacheFile(IFile $file, FileFormatter $formatter, string $targetPath): bool
    {
        if ($file instanceof ICacheStateful && $file->getIsCached($formatter->name)) {
            return true;
        }

        return (new Saver($file, $this->cacheFS, $targetPath))->save($formatter);
    }
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;
    }
1354042
private static long fileCreationTime(File targetFile)
  {
    if (!targetFile.exists())
    {
      LOGGER.debug("File not exists. File: {}", targetFile);
      return -1;
    }
    try
    {
      Path cacheFileLockPath = Paths.get(targetFile.getAbsolutePath());
      BasicFileAttributes attr = Files.readAttributes(
          cacheFileLockPath, BasicFileAttributes.class);
      return attr.creationTime().toMillis();
    }
    catch (IOException ex)
    {
      LOGGER.debug(
          "Failed to get creation time. File/Dir: {}, Err: {}",
          targetFile, ex);
    }
    return -1;
  }
1011799
public static boolean fileExists(final File target) {
        return AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
            @Override
            public Boolean run() {
                return target.exists();
            }

        });
    }