Créer un fichier temporaire en Java

Dans ce tutoriel nous allons découvrir comment créer un fichier temporaire en Java.
 
 

Exemple:
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
import java.io.*;
public class Main
{
public static void main(String[] args)
{
try{
//créer un fichier temporaire
File tmp = File.createTempFile("monFichier", ".tmp");
System.out.println("Fichier Temporaire : " + tmp.getAbsolutePath());
}catch(IOException e){
e.printStackTrace();
}
}
}
import java.io.*; public class Main { public static void main(String[] args) { try{ //créer un fichier temporaire File tmp = File.createTempFile("monFichier", ".tmp"); System.out.println("Fichier Temporaire : " + tmp.getAbsolutePath()); }catch(IOException e){ e.printStackTrace(); } } }
import java.io.*;

public class Main
{
    public static void main(String[] args)
    {	
    	try{
    	   //créer un fichier temporaire
    	   File tmp = File.createTempFile("monFichier", ".tmp"); 
    		
    	   System.out.println("Fichier Temporaire : " + tmp.getAbsolutePath());
    		
    	}catch(IOException e){	
    	   e.printStackTrace();
    	}
    }
}

 
Sortie:
 

 

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *