Home  >  Article  >  Java  >  Java Example - Create file in specified directory

Java Example - Create file in specified directory

黄舟
黄舟Original
2017-02-15 10:28:051091browse

The following example demonstrates using the file.createTempFile() method of the File class to create a file in the specified directory:

/*
 author by w3cschool.cc
 Main.java
 */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());
   }}

The output result of running the above code is:

C:\JavaTemp37056.javatemp

The above is Java example - Create the content of the file in the specified directory. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn