Home >Java >javaTutorial >Java Example - File Writing

Java Example - File Writing

黄舟
黄舟Original
2017-02-15 10:04:541233browse

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) {
      }
   }}

The output result of running the above code is:

文件创建成功!

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

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