How to find temporary file path using java


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(tempfile", ".tmp");

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

//Get tempropary file path
String absolutePath = temp.getAbsolutePath();
String tempFilePath = absolutePath.
substring(0,absolutePath.lastIndexOf(File.separator));

System.out.println("Temp file path : " + tempFilePath);

}catch(IOException e){

e.printStackTrace();

}

}
}

 

SHARE

    Blogger Comment
    Facebook Comment

0 comments :

Post a Comment