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://www.codercto.com/courses/l/12.html

查看所有标签

The Shallows

The Shallows

Nicholas Carr / W. W. Norton & Company / 2010-6-15 / USD 26.95

"Is Google making us stupid?" When Nicholas Carr posed that question, in a celebrated Atlantic Monthly cover story, he tapped into a well of anxiety about how the Internet is changing us. He also crys......一起来看看 《The Shallows》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

SHA 加密
SHA 加密

SHA 加密工具

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具