How to create a file in a specified directory in java

  • by

Creating file in a specified directory in java:-
Following code demonstrate how to create file in a specified directory using File.createTempFile() method.
import java.io.File;
public class Main
{
public static void main(String[] args)
throws Exception
{
File file = null;
File dir = new File(“C:/”);
file = File.createTempFile
(“JavaTemp”, “.javatemp”, dir);
System.out.println(file.getPath());
}
}

Leave a Reply