Home > Java > javaTutorial > body text

Java Example - File Writing

黄舟
Release: 2017-02-15 10:04:54
Original
1185 people have browsed it

The following example demonstrates using the write() method to write content to a file:

/*
 author by w3cschool.cc
 Main.java
 */import java.io.*;public class Main {
   public static void main(String[] args)  {
      try {
         BufferedWriter out = new
         BufferedWriter(new FileWriter("outfilename"));
         out.write("w3cschool菜鸟教程");
         out.close();
         System.out.println         ("文件创建成功!");
      }
      catch (IOException e) {
      }
   }}
Copy after login

The output result of running the above code is:

文件创建成功!
Copy after login

The current directory after successful creation The following will generate a file named outfilename and write the "w3cschool novice tutorial" string into the file.

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

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