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

查看所有标签

Learning Python, 5th Edition

Learning Python, 5th Edition

Mark Lutz / O'Reilly Media / 2013-7-6 / USD 64.99

If you want to write efficient, high-quality code that's easily integrated with other languages and tools, this hands-on book will help you be productive with Python quickly. Learning Python, Fifth Ed......一起来看看 《Learning Python, 5th Edition》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

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

URL 编码/解码

MD5 加密
MD5 加密

MD5 加密工具