本文整理汇总了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();
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
}
示例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);
}
}
示例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;
}
示例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());
}
示例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());
}
示例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 */
);
}
示例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();
}
}
示例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);
}
示例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;
}
示例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);
}
示例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());
}