当前位置: 技术问答>java相关
PrintWriter和FileWriter这两个类有什么区别
来源: 互联网 发布时间:2017-03-11
本文导语: PrintWriter和FileWriter这两个类有什么区别? 我要在linux系统下写文件,用哪个类合适? | java.io Class FileWriter java.lang.Object | +--java.io.Writer | +--java.io.OutputStreamWriter ...
PrintWriter和FileWriter这两个类有什么区别?
我要在linux系统下写文件,用哪个类合适?
我要在linux系统下写文件,用哪个类合适?
|
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.
写文件用前者比较合适吧.
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.
写文件用前者比较合适吧.
|
写文件最佳组合
PrintWriter out = new PrintWriter(
new BufferedWriter(
new FileWriter(filename)))
PrintWriter 提供print系方法
BufferedWriter 提供缓冲,用以加速
FileWriter 用于写文件
PrintWriter out = new PrintWriter(
new BufferedWriter(
new FileWriter(filename)))
PrintWriter 提供print系方法
BufferedWriter 提供缓冲,用以加速
FileWriter 用于写文件
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。