日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > java >内容正文

java

java创建临时文件_用Java创建一个临时文件

發(fā)布時(shí)間:2023/12/1 java 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java创建临时文件_用Java创建一个临时文件 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

java創(chuàng)建臨時(shí)文件

The task is to create a temporary file in Java.

任務(wù)是用Java創(chuàng)建一個(gè)臨時(shí)文件。

Creating a temporary file

創(chuàng)建一個(gè)臨時(shí)文件

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中創(chuàng)建一個(gè)臨時(shí)文件,我們使用“ File”類(lèi)的createTempFile()方法 。 用File對(duì)象調(diào)用createTempFile()方法 ,該對(duì)象應(yīng)使用文件名(和路徑,如果要指定)初始化。

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

createTempFile()方法返回一個(gè)File對(duì)象,通過(guò)使用getName()方法 ,我們可以訪問(wèn)臨時(shí)文件名。

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.

此方法接受兩個(gè)參數(shù)1) file_name和2) file_extension name。 如果file_extension為null ,則默認(rèn)文件擴(kuò)展名為.tmp 。

Package to use: import java.io.*;

要使用的包: import java.io. *;

Syntax:

句法:

//file object creationFile one = null;File two = null;//temporary file creationone = File.createTempFile("file_name", "extension");two = File.createTempFile("file_name", "extension");

Java代碼創(chuàng)建一個(gè)臨時(shí)文件 (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 resultsFile one = null;File two = null;try {//creating temporary file1 with extension '.javatemp'one = File.createTempFile("sample1", ".javatemp");//creating temporary file2 without using nulltwo = 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

翻譯自: https://www.includehelp.com/java-programs/create-a-temporary-file-in-java.aspx

java創(chuàng)建臨時(shí)文件

總結(jié)

以上是生活随笔為你收集整理的java创建临时文件_用Java创建一个临时文件的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。