org.apache.tools.ant.util.FileUtils.createTempFile()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(7.3k)|赞(0)|评价(0)|浏览(116)

本文整理了Java中org.apache.tools.ant.util.FileUtils.createTempFile()方法的一些代码示例,展示了FileUtils.createTempFile()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileUtils.createTempFile()方法的具体详情如下:
包路径:org.apache.tools.ant.util.FileUtils
类名称:FileUtils
方法名:createTempFile

FileUtils.createTempFile介绍

[英]Create a File object for a temporary file in a given directory. Without actually creating the file.

The file denoted by the returned abstract pathname did not exist before this method was invoked, any subsequent invocation of this method will yield a different file name.

The filename is prefixNNNNNsuffix where NNNN is a random number.
[中]

代码示例

代码示例来源:origin: org.apache.ant/ant

/**
 * Create a File object for a temporary file in a given directory. Without
 * actually creating the file.
 *
 * <p>
 * The file denoted by the returned abstract pathname did not exist before
 * this method was invoked, any subsequent invocation of this method will
 * yield a different file name.
 * </p>
 * <p>
 * The filename is prefixNNNNNsuffix where NNNN is a random number.
 * </p>
 *
 * @param prefix
 *            prefix before the random number.
 * @param suffix
 *            file extension; include the '.'.
 * @param parentDir
 *            Directory to create the temporary file in; java.io.tmpdir used
 *            if not specified.
 *
 * @deprecated since ant 1.7.1 use createTempFile(String, String, File,
 * boolean, boolean) instead.
 * @return a File reference to the new, nonexistent temporary file.
 */
@Deprecated
public File createTempFile(String prefix, String suffix, File parentDir) {
  return createTempFile(prefix, suffix, parentDir, false, false);
}

代码示例来源:origin: org.apache.ant/ant

public File createTempFile(String prefix, String suffix,
    File parentDir, boolean deleteOnExit) {
  return createTempFile(prefix, suffix, parentDir, deleteOnExit, false);

代码示例来源:origin: org.apache.ant/ant

/** rename the zip file. */
private File renameFile() {
  final File renamedFile = FILE_UTILS.createTempFile(
    "zip", ".tmp", zipFile.getParentFile(), true, false);
  try {
    FILE_UTILS.rename(zipFile, renamedFile);
  } catch (final SecurityException | IOException e) {
    throw new BuildException(
      "Unable to rename old file (%s) to temporary file",
      zipFile.getAbsolutePath());
  }
  return renamedFile;
}

代码示例来源:origin: org.apache.ant/ant

/**
 * Writes the command into a temporary DCL script and returns the
 * corresponding File object.
 * It is the job of the caller to delete the file on exit.
 * @param cmds the command.
 * @return the file containing the command.
 * @throws IOException if there is an error writing to the file.
 */
public static File createVmsJavaOptionFile(String[] cmds)
    throws IOException {
  File script = FILE_UTILS.createTempFile("ANT", ".JAVA_OPTS", null, false, true);
  try (BufferedWriter out = new BufferedWriter(new FileWriter(script))) {
    for (String cmd : cmds) {
      out.write(cmd);
      out.newLine();
    }
  }
  return script;
}

代码示例来源:origin: org.apache.ant/ant

/**
 * Creates a list file.  This temporary file contains a list of all files
 * to be included in the cab, one file per line.
 *
 * <p>This method expects to only be called on Windows and thus
 * quotes the file names.</p>
 * @param files the list of files to use.
 * @return the list file created.
 * @throws IOException if there is an error.
 */
protected File createListFile(Vector<String> files)
  throws IOException {
  File listFile = FILE_UTILS.createTempFile("ant", "", null, true, true);
  try (BufferedWriter writer =
    new BufferedWriter(new FileWriter(listFile))) {
    for (String f : files) {
      String s = String.format("\"%s\"", f);
      writer.write(s);
      writer.newLine();
    }
  }
  return listFile;
}

代码示例来源:origin: org.apache.ant/ant

private File createCommandFile(String[] cmd, String[] env)
  throws IOException {
  File script = FILE_UTILS.createTempFile("ANT", ".COM", null, true, true);
  try (BufferedWriter out = new BufferedWriter(new FileWriter(script))) {
    // add the environment as logicals to the DCL script
    if (env != null) {
      int eqIndex;
      for (String variable : env) {
        eqIndex = variable.indexOf('=');
        if (eqIndex != -1) {
          out.write("$ DEFINE/NOLOG ");
          out.write(variable.substring(0, eqIndex));
          out.write(" \"");
          out.write(variable.substring(eqIndex + 1));
          out.write('\"');
          out.newLine();
        }
      }
    }
    out.write("$ " + cmd[0]);
    for (int i = 1; i < cmd.length; i++) {
      out.write(" -");
      out.newLine();
      out.write(cmd[i]);
    }
  }
  return script;
}

代码示例来源:origin: apache/groovy

private void createNewArgs(String txt) throws IOException {
  final String[] args = cmdline.getCommandline();
  // Temporary file - delete on exit, create (assured unique name).
  final File tempFile = FileUtils.getFileUtils().createTempFile(PREFIX, SUFFIX, null, true, true);
  final String[] commandline = new String[args.length + 1];
  ResourceGroovyMethods.write(tempFile, txt);
  commandline[0] = tempFile.getCanonicalPath();
  System.arraycopy(args, 0, commandline, 1, args.length);
  super.clearArgs();
  for (String arg : commandline) {
    final Commandline.Argument argument = super.createArg();
    argument.setValue(arg);
  }
}

代码示例来源:origin: org.apache.ant/ant

/**
   * Creates the temporary file.
   *
   * @exception  BuildException  if something goes wrong with the build
   */
  @Override
  public void execute() throws BuildException {
    if (property == null || property.isEmpty()) {
      throw new BuildException("no property specified");
    }
    if (destDir == null) {
      destDir = getProject().resolveFile(".");
    }
    File tfile = FILE_UTILS.createTempFile(prefix, suffix, destDir,
          deleteOnExit, createFile);
    getProject().setNewProperty(property, tfile.toString());
  }
}

代码示例来源:origin: org.apache.ant/ant

optionsTmpFile = FILE_UTILS.createTempFile(
  "javadocOptions", "", null, true, true);
final String[] listOpt = toExecute.getArguments();

代码示例来源:origin: org.apache.ant/ant

BufferedWriter out = null;
try {
  tmpFile = FileUtils.getFileUtils().createTempFile("jikes",
      "tmp", null, false, true);
  out = new BufferedWriter(new FileWriter(tmpFile));

代码示例来源:origin: org.apache.ant/ant

final File temp = FILE_UTILS.createTempFile("symlink", ".tmp",
                   target.getParentFile(), false,
                   false);

代码示例来源:origin: org.apache.ant/ant

File temp = FILE_UTILS.createTempFile("replace", ".txt", null, true, true);
try {
  boolean changes = false;

代码示例来源:origin: org.apache.ant/ant

File temp = FILE_UTILS.createTempFile("rep", ".tmp",
    src.getParentFile(), false, true);
try {

代码示例来源:origin: org.apache.ant/ant

fcv.add(fc);
File tmpFile = FILE_UTILS.createTempFile("fixcrlf", "", null, true, true);
try {
  FILE_UTILS.copyFile(srcFile, tmpFile, null, fcv, true, false,

代码示例来源:origin: org.apache.ant/ant

&& firstFileName >= 0) {
try {
  tmpFile = FILE_UTILS.createTempFile(
    "files", "", getJavac().getTempdir(), true, true);
  try (BufferedWriter out =

代码示例来源:origin: org.apache.ant/ant

File tmpFile = fu.createTempFile("modified-", ".tmp", null, true, false);
Resource tmpResource = new FileResource(tmpFile);
ResourceUtils.copyResource(resource, tmpResource);

代码示例来源:origin: org.apache.ant/ant

outFile = FILE_UTILS.createTempFile("ant", "", null, true, true);
exec.setOutput(outFile);

代码示例来源:origin: org.apache.ant/ant

handlePackageNames();
tmpFile = FILE_UTILS.createTempFile("cvstagdiff", ".log", null,
                  true, true);
setOutput(tmpFile);

代码示例来源:origin: org.apache.ant/ant

tmpList = FILE_UTILS.createTempFile("javadoc", "", null, true, true);
toExecute.createArgument()
  .setValue("@" + tmpList.getAbsolutePath());

代码示例来源:origin: org.apache.ant/ant-junit

/**
 * Create a temporary file to pass the properties to a new process.
 * Will auto-delete on (graceful) exit.
 * The file will be in the project basedir unless tmpDir declares
 * something else.
 * @param prefix String
 * @return created file
 */
private File createTempPropertiesFile(final String prefix) {
  return FILE_UTILS.createTempFile(prefix, ".properties",
    tmpDir != null ? tmpDir : getProject().getBaseDir(), true, true);
}

相关文章