How to get the temporary file path in Java?

an Example for to get the temporary file path in Java

package com.nourit.javaIO;

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

public class GetTempFilePath {

  public static void main(String[] args) {
    try {
      // create a temp file
      File temp = File.createTempFile("nouritTemp-file-name", ".tmp");
      // Get tempropary file path
      String absolutePath = temp.getAbsolutePath();
      System.out.println("Temp file path : " + absolutePath);

    } catch (IOException e) {

      e.printStackTrace();

    }
  }
}

Outout:

Temp file : C:\Users\MOHAME~1.PRO\AppData\Local\Temp\nouritTemp-file-name7955618864583162693.tmp

 

NOUR-IT

IT Training Center for Java and Web technology. If you enjoy and like our tutorials and believe in our mission, Please Subscribe us on Youtube and follow us on Twitter, or befriend us on Facebook or Google Plus.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.

*