Home > Java > javaTutorial > body text

Java Example - Create Temporary File

黄舟
Release: 2017-02-15 10:11:30
Original
1411 people have browsed it

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

The output result of running the above code is:

临时文件已创建:
Copy after login

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)!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!