開発者ドキュメント

Javaで一時ファイルを作成する方法

次に、Javaで一時ファイルを作成する例を示します。


package com.mkyong.file;

import java.io.File;
import java.io.IOException;

public class CreateTempFileExample
{
    public static void main(String[]args)
    {

        try{

          //create a temp file
           File temp = File.createTempFile("temp-file-name", ".tmp");

           System.out.println("Temp file : " + temp.getAbsolutePath());

        }catch(IOException e){

           e.printStackTrace();

        }

    }
}

結果

Temp file : C:\Users\mkyong\AppData\Local\Temp\temp-file-name623426.tmp
モバイルバージョンを終了