Java 实例 - 向文件中追加数据

Java 教程 · 2019-02-10 20:59:52

以下实例演示了使用 filewriter 方法向文件中追加数据:

Main.java 文件

import java.io.*; public class Main { public static void main(String[] args) throws Exception { try { BufferedWriter out = new BufferedWriter(new FileWriter("filename")); out.write("aString1\n"); out.close(); out = new BufferedWriter(new FileWriter("filename",true)); out.write("aString2"); out.close(); BufferedReader in = new BufferedReader(new FileReader("filename")); String str; while ((str = in.readLine()) != null) { System.out.println(str); } in.close(); } catch (IOException e) { System.out.println("exception occoured"+ e); } } }

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

aString1
aString2

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

查看所有标签

AI Algorithms, Data Structures, and Idioms in Prolog, Lisp, and

AI Algorithms, Data Structures, and Idioms in Prolog, Lisp, and

George F. Luger、William A Stubblefield / Addison Wesley / 2008-09-04 / USD 22.20

This book is designed for three primary purposes. The first is as a programming language component of a general class in Artificial Intelligence. From this viewpoint, the authors see as essential that......一起来看看 《AI Algorithms, Data Structures, and Idioms in Prolog, Lisp, and 》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

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

Markdown 在线编辑器

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换