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

Java Example - Create file in specified directory

黄舟
Release: 2017-02-15 10:28:05
Original
1137 people have browsed it

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

The output result of running the above code is:

C:\JavaTemp37056.javatemp
Copy after login

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 (m.sbmmt.com)!



Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template