当前位置: 首页>>代码示例>>Java>>正文


Java File.createTempFile方法代码示例

本文整理汇总了Java中java.io.File.createTempFile方法的典型用法代码示例。如果您正苦于以下问题:Java File.createTempFile方法的具体用法?Java File.createTempFile怎么用?Java File.createTempFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.io.File的用法示例。


在下文中一共展示了File.createTempFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createTempFile

import java.io.File; //导入方法依赖的package包/类
@BeforeClass
public static void createTempFile() throws Exception {

  File tempFile;
  while (true) {
    tempFile = File.createTempFile("drillFSTest", ".txt");
    if (tempFile.exists()) {
      boolean success = tempFile.delete();
      if (success) {
        break;
      }
    }
  }

  // Write some data
  PrintWriter printWriter = new PrintWriter(tempFile);
  for (int i=1; i<=200000; i++) {
    printWriter.println (String.format("%d, key_%d", i, i));
  }
  printWriter.close();

  tempFilePath = tempFile.getPath();
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:24,代码来源:TestDrillFileSystem.java

示例2: createTempJar

import java.io.File; //导入方法依赖的package包/类
/**
 * 创建临时文件*.jar
 * 
 * @param root
 * @return
 * @throws IOException
 */
public static File createTempJar(String root) throws IOException {
    if (!new File(root).exists()) {
        return null;
    }

    final File jarFile = File.createTempFile("EJob-", ".jar", new File(System
            .getProperty("java.io.tmpdir")));

    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override
        public void run() {
            jarFile.delete();
        }
    });

    JarOutputStream out = new JarOutputStream(new FileOutputStream(jarFile));
    createTempJarInner(out, new File(root), "");
    out.flush();
    out.close();
    return jarFile;
}
 
开发者ID:liuhaozzu,项目名称:big_data,代码行数:29,代码来源:EJob.java

示例3: createTempFileFrom

import java.io.File; //导入方法依赖的package包/类
private File createTempFileFrom(String resource) throws IOException {
    InputStream is = getClass().getResourceAsStream("resources/"+resource);
    File f = File.createTempFile("LR_", resource);
    f.deleteOnExit();
    OutputStream out = new FileOutputStream(f);
    try {
        byte[] buffer = new byte[1024];
        int l;
        while((l = is.read(buffer)) > 0) {
            out.write(buffer, 0, l);
        }
    } finally {
        is.close();
        out.close();
    }
    return f;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:LogRecordsRepairTest.java

示例4: setUp

import java.io.File; //导入方法依赖的package包/类
static void setUp() throws Exception {
    testarray = new float[1024];
    for (int i = 0; i < 1024; i++) {
        double ii = i / 1024.0;
        ii = ii * ii;
        testarray[i] = (float)Math.sin(10*ii*2*Math.PI);
        testarray[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);
        testarray[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);
        testarray[i] *= 0.3;
    }
    test_byte_array = new byte[testarray.length*2];
    AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
    test_file = File.createTempFile("test", ".raw");
    FileOutputStream fos = new FileOutputStream(test_file);
    fos.write(test_byte_array);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:17,代码来源:Load.java

示例5: createTempFile

import java.io.File; //导入方法依赖的package包/类
private File createTempFile() {
    try {
        File cmdFile = File.createTempFile("input", "jcmd");
        cmdFile.deleteOnExit();
        return cmdFile;
    } catch (IOException e) {
        throw new CommandExecutorException("Could not create temporary file", e);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:FileJcmdExecutor.java

示例6: setUp

import java.io.File; //导入方法依赖的package包/类
static void setUp() throws Exception {
    testarray = new float[1024];
    for (int i = 0; i < 1024; i++) {
        double ii = i / 1024.0;
        ii = ii * ii;
        testarray[i] = (float)Math.sin(10*ii*2*Math.PI);
        testarray[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);
        testarray[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);
        testarray[i] *= 0.3;
    }
    test_byte_array = new byte[testarray.length*2];
    AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
    test_file = File.createTempFile("test", ".raw");
    try (FileOutputStream fos = new FileOutputStream(test_file)) {
        fos.write(test_byte_array);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:Skip.java

示例7: createTmpDir

import java.io.File; //导入方法依赖的package包/类
static File createTmpDir(File parentDir, boolean createInitFile) throws IOException {
    File tmpFile = File.createTempFile("test", ".junit", parentDir);
    // don't delete tmpFile - this ensures we don't attempt to create
    // a tmpDir with a duplicate name
    File tmpDir = new File(tmpFile + ".dir");
    Assert.assertFalse(tmpDir.exists()); // never true if tmpfile does it's job
    Assert.assertTrue(tmpDir.mkdirs());

    // todo not every tmp directory needs this file
    if (createInitFile) {
        createInitializeFile(tmpDir);
    }

    return tmpDir;
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:16,代码来源:ClientBase.java

示例8: testSaveFigNoImpactToShow

import java.io.File; //导入方法依赖的package包/类
@Test
public void testSaveFigNoImpactToShow() throws IOException, PythonExecutionException {
    File tmpFile = File.createTempFile("savefig", ".png");
    tmpFile.deleteOnExit();

    Plot plt = new PlotImpl(DRY_RUN);
    plt.plot().add(Arrays.asList(1.3, 2));
    plt.title("Title!");
    plt.savefig(tmpFile.getAbsolutePath());
    plt.executeSilently();
    plt.show();

    Assert.assertTrue(tmpFile.exists());
}
 
开发者ID:sh0nk,项目名称:matplotlib4j,代码行数:15,代码来源:SaveFigTest.java

示例9: VerificationError

import java.io.File; //导入方法依赖的package包/类
/**
 * Construct a new VerificationError from an Exception (which was thrown while launching/managing
 * the verification. These will typically not come from the verification engine itself).
 *
 * @param ex The exception to construct a VerificationError from
 */
public VerificationError(Exception ex) {
  this.reason = Reason.EXCEPTION;
  try {
    logFile = File.createTempFile("verification-exception", "");
    PrintWriter writer = new PrintWriter(
        new OutputStreamWriter(new FileOutputStream(logFile), StandardCharsets.UTF_8), true);
    ex.printStackTrace(writer);
  } catch (IOException exception) {
    // Do nothing if writing the exception to the log throws an exception
    logFile = null;
  }
  errorMessages.put(Reason.EXCEPTION, ex.getMessage());
}
 
开发者ID:VerifAPS,项目名称:stvs,代码行数:20,代码来源:VerificationError.java

示例10: createTempImageFile

import java.io.File; //导入方法依赖的package包/类
/**
 * Creates the temporary image file in the cache directory.
 *
 * @return The temporary image file.
 * @throws IOException Thrown if there is an error creating the file
 */
static File createTempImageFile(Context context) throws IOException {
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss",
            Locale.getDefault()).format(new Date());
    String imageFileName = "JPEG_" + timeStamp + "_";
    //Returns the absolute path to the application specific cache directory on the filesystem.
    File storageDir = context.getExternalCacheDir();

    return File.createTempFile(
            imageFileName,  /* prefix */
            ".jpg",         /* suffix */
            storageDir      /* directory */
    );
}
 
开发者ID:Masquerade0097,项目名称:Face_Animate,代码行数:20,代码来源:BitmapUtils.java

示例11: imageOut

import java.io.File; //导入方法依赖的package包/类
public void imageOut(String fileName) {

    File f = null;
    try {
      f = File.createTempFile("tmp_", "svg");
      FileOutputStream fs = new FileOutputStream(f);
      streamOut(fs);
      fs.flush();
      fs.close();
      String[] options = new String[13];
      // destination
      options[0] = Main.CL_OPTION_OUTPUT;
      options[1] = fileName;
      // destination type
      options[2] = Main.CL_OPTION_MIME_TYPE;
      options[3] = getMimeType(fileName);
      // quality (for JPEG)
      options[4] = Main.CL_OPTION_QUALITY;
      options[5] = "0.8";
      // resolution
      options[6] = Main.CL_OPTION_DPI;
      options[7] = "300";
      // resolution
      options[8] = Main.CL_OPTION_WIDTH;
      options[9] = "1024";
      // resolution
      options[10] = Main.CL_OPTION_BACKGROUND_COLOR;
      options[11] = "255.255.255.255";
      // input file
      options[12] = f.getAbsolutePath();
      // convert
      Main c = new Main(options);
      c.execute();
      // remove temporary file
      f.delete();
    }
    catch (IOException e) {
      e.printStackTrace();
    }
  }
 
开发者ID:etomica,项目名称:etomica,代码行数:41,代码来源:GraphMap.java

示例12: executeSample

import java.io.File; //导入方法依赖的package包/类
@Override
public RequestHandle executeSample(AsyncHttpClient client, String URL, Header[] headers, HttpEntity entity, ResponseHandlerInterface responseHandler) {
    RequestParams rParams = new RequestParams();
    rParams.put("sample_key", "Sample String");
    try {
        File sample_file = File.createTempFile("temp_", "_handled", getCacheDir());
        rParams.put("sample_file", sample_file);
    } catch (IOException e) {
        Log.e(LOG_TAG, "Cannot add sample file", e);
    }
    return client.post(this, URL, headers, rParams, "multipart/form-data", responseHandler);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:ContentTypeForHttpEntitySample.java

示例13: createTmpDir

import java.io.File; //导入方法依赖的package包/类
static File createTmpDir(File parentDir) throws IOException {
    File tmpFile = File.createTempFile("test", ".junit", parentDir);
    // don't delete tmpFile - this ensures we don't attempt to create
    // a tmpDir with a duplicate name
    File tmpDir = new File(tmpFile + ".dir");
    Assert.assertFalse(tmpDir.exists()); // never true if tmpfile does it's job
    Assert.assertTrue(tmpDir.mkdirs());

    return tmpDir;
}
 
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:11,代码来源:ClientBase.java

示例14: testBuild

import java.io.File; //导入方法依赖的package包/类
@Test
public void testBuild() throws Exception {
	
	@SuppressWarnings("rawtypes")
	UniquidNodeImpl.UniquidNodeBuilder builder = new UniquidNodeImpl.UniquidNodeBuilder();
	
	NetworkParameters parameters = UniquidRegTest.get();
	File providerFile = File.createTempFile("provider", ".wallet");
	File userFile = File.createTempFile("user", ".wallet");
	File chainFile = File.createTempFile("chain", ".chain");
	File userChainFile = File.createTempFile("userchain", ".chain");
	RegisterFactory dummyRegister = new DummyRegisterFactory(null, null, new DummyTransactionManager());
	String machineName = "machineName";

	builder.setNetworkParameters(parameters);
	builder.setProviderFile(providerFile);
	builder.setUserFile(userFile);
	builder.setProviderChainFile(chainFile);
	builder.setUserChainFile(userChainFile);
	builder.setRegisterFactory(dummyRegister);
	builder.setNodeName(machineName);
	
	UniquidNodeImpl uniquidNode = builder.build();
	
	Assert.assertNotNull(uniquidNode);
	
}
 
开发者ID:uniquid,项目名称:uidcore-java,代码行数:28,代码来源:UniquidNodeImplBuilderTest.java

示例15: testDeleteDir

import java.io.File; //导入方法依赖的package包/类
@Test
public void testDeleteDir() throws IOException {
  File dir = new File("testDirName");
  dir.mkdir();
  File file = File.createTempFile("testFile", null, dir);
  assertTrue(dir.exists());
  assertTrue(file.exists());
  FileUtil.delete(dir);
  assertFalse(file.exists());
  assertFalse(dir.exists());
}
 
开发者ID:ampool,项目名称:monarch,代码行数:12,代码来源:FileUtilJUnitTest.java


注:本文中的java.io.File.createTempFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。