Home  >  Article  >  Java  >  Java Example - Create Temporary File

Java Example - Create Temporary File

黄舟
黄舟Original
2017-02-15 10:11:301354browse

The following example demonstrates using the createTempFile() method of the File class to create a temporary file:

/*
 author by w3cschool.cc
 Main.java
 */import java.io.*;public class Main {
   public static void main(String[] args) 
   throws Exception {
      File temp = File.createTempFile      ("pattern", ".suffix");
      temp.deleteOnExit();
      BufferedWriter out = new BufferedWriter
      (new FileWriter(temp));
      out.write("aString");
      System.out.println("临时文件已创建:");
      out.close();
   }}

The output result of running the above code is:

临时文件已创建:

The above is Java Example - Create the contents of a temporary file. 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