PrintWriter和FileWriter这两个类有什么区别

woxin 2002-12-04 03:04:58
PrintWriter和FileWriter这两个类有什么区别?
我要在linux系统下写文件,用哪个类合适?
...全文
440 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
ilka 2002-12-04
  • 打赏
  • 举报
回复
写文件最佳组合
PrintWriter out = new PrintWriter(
new BufferedWriter(
new FileWriter(filename)))
PrintWriter 提供print系方法
BufferedWriter 提供缓冲,用以加速
FileWriter 用于写文件
yihua_cai 2002-12-04
  • 打赏
  • 举报
回复
java.io
Class FileWriter
java.lang.Object
|
+--java.io.Writer
|
+--java.io.OutputStreamWriter
|
+--java.io.FileWriter

public class FileWriter

Convenience class for writing character files. The constructors of this class assume that the default character encoding and the default byte-buffer size are acceptable. To specify these values yourself, construct an OutputStreamWriter on a FileOutputStream.



java.io
Class PrintWriter
java.lang.Object
|
+--java.io.Writer
|
+--java.io.PrintWriter

public class PrintWriter

Print formatted representations of objects to a text-output stream. This class implements all of the print methods found in PrintStream. It does not contain methods for writing raw bytes, for which a program should use unencoded byte streams.


写文件用前者比较合适吧.

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧