Tutorials Point


  Java Basics Examples
  Java Tutorial
  Java Useful Resources
  Selected Reading

© 2011 TutorialsPoint.COM


  Home     References     Discussion Forums     About TP  

Java Examples - Creation of File


previous next AddThis Social Bookmark Button


Problem Description:

How to create a file in a specified directory ?

Solution:

This example demonstrates how to create a file in a specified directory using File.createTempFile() method of File class.

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());
   }
}

Result:

The above code sample will produce the following result.

C:\JavaTemp37056.javatemp


previous next Printer Friendly



  

Advertisement

Online Image Processing

Indian Baby Names