java 进程临时文件生成 java创建临时表

您所在的位置:网站首页 创建一个临时表 java 进程临时文件生成 java创建临时表

java 进程临时文件生成 java创建临时表

2023-06-09 05:54| 来源: 网络整理| 查看: 265

java创建临时文件

The task is to create a temporary file in Java.

任务是用Java创建一个临时文件。

Creating a temporary file

创建一个临时文件

To create a temporary file in java – we use createTempFile() method of "File" class. The createTempFile() method is called with the File object which should be initialized with the file name (and path if you want to specify).

在Java中创建一个临时文件,我们使用“ File”类的createTempFile()方法 。 用File对象调用createTempFile()方法 ,该对象应使用文件名(和路径,如果要指定)初始化。

The createTempFile() method returns a File object, and by using getName() method, we can access the temporary file name.

createTempFile()方法返回一个File对象,通过使用getName()方法 ,我们可以访问临时文件名。

This method accepts two arguments 1) file_name and 2) file_extension name. If the file_extension is null, the default file extension will be .tmp.

此方法接受两个参数1) file_name和2) file_extension name。 如果file_extension为null ,则默认文件扩展名为.tmp 。

Package to use: import java.io.*;

要使用的包:

Syntax:

句法:

//file object creation File one = null; File two = null; //temporary file creation one = File.createTempFile("file_name", "extension"); two = File.createTempFile("file_name", "extension");(Java code to create a temporary file)// Java code to create a temporary file import java.io.*; public class Main { public static void main(String[] args) { //file object creation to store results File one = null; File two = null; try { //creating temporary file1 with extension '.javatemp' one = File.createTempFile("sample1", ".javatemp"); //creating temporary file2 without using null two = File.createTempFile("sample2", null); System.out.println("file created: " + one.getPath()); System.out.println("file created: " + two.getPath()); } catch (IOException exp) { System.out.println("Error in creating temporary file: " + exp); } } }

Output

输出量

file created: /tmp/sample14223766203657377545.javatemp file created: /tmp/sample22708977934903691208.tmp



【本文地址】


今日新闻


推荐新闻


    CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3