Java 实例 - 文件写入

Java 教程 · 2019-02-10 19:56:49

以下实例演示了使用 write() 方法向文件写入内容:

实例

/* author by codercto.com Main.java */ import java.io.*; public class Main { public static void main(String[] args) { try { BufferedWriter out = new BufferedWriter(new FileWriter("codercto.txt")); out.write("码农教程"); out.close(); System.out.println("文件创建成功!"); } catch (IOException e) { } } }

以上代码运行输出结果为:

文件创建成功!

创建成功后当前目录下就会生成一个名为 codercto.txt 的文件并将 "码农教程" 字符串写入该文件。

点击查看所有 Java 教程 文章: https://codercto.com/courses/l/12.html

查看所有标签

The Art of Computer Programming, Volume 2

The Art of Computer Programming, Volume 2

Knuth, Donald E. / Addison-Wesley Professional / 1997-11-04 / USD 79.99

Finally, after a wait of more than thirty-five years, the first part of Volume 4 is at last ready for publication. Check out the boxed set that brings together Volumes 1 - 4A in one elegant case, and ......一起来看看 《The Art of Computer Programming, Volume 2》 这本书的介绍吧!

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

URL 编码/解码
URL 编码/解码

URL 编码/解码

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器