Java IO流之PrintStream分析
簡(jiǎn)介
PrintStream繼承了FilterOutputStream.是"裝飾類"的一種,所以屬于字節(jié)流體系中(與PrintStream相似的流PrintWriter繼承于Writer,屬于字符流體系中),為其他的輸出流添加功能.使它們能夠方便打印各種數(shù)據(jù)值的表示形式.此外,值得注意的是:
- 與其他流不同的是,PrintStream流永遠(yuǎn)不會(huì)拋出異常.因?yàn)樽隽藅ry{}catch(){}會(huì)將異常捕獲,出現(xiàn)異常情況會(huì)在內(nèi)部設(shè)置標(biāo)識(shí),通過(guò)checkError()獲取此標(biāo)識(shí).
- PrintStream流有自動(dòng)刷新機(jī)制,例如當(dāng)向PrintStream流中寫(xiě)入一個(gè)字節(jié)數(shù)組后自動(dòng)調(diào)用flush()方法.
PrintStream流打印的字符通過(guò)平臺(tái)默認(rèn)的編碼方式轉(zhuǎn)換成字節(jié),在寫(xiě)入的是字符,而不是字節(jié)的情況下,應(yīng)該使用PrintWriter.PrintStream流中基本所有的print(Object obj)重載方法和println(Object obj)重載方法都是通過(guò)將對(duì)應(yīng)數(shù)據(jù)先轉(zhuǎn)換成字符串,然后調(diào)用write()方法寫(xiě)到底層輸出流中.常見(jiàn)用到PrintStream流:System.out就被包裝成PrintStream流,System.err也是PrintStream流,注意System.in不是PrintStream,是沒(méi)有包裝過(guò)的OutputStream.所以System.in不能直接使用.
PrintStream流不是直接將數(shù)據(jù)寫(xiě)到文件的流,需要傳入底層輸出流out,而且要實(shí)現(xiàn)指定編碼方式,需要中間流OutputStreamWriter,OutputStreamWriter流實(shí)現(xiàn)了字符流以指定編碼方式轉(zhuǎn)換成字節(jié)流.此外為了提高寫(xiě)入文件的效率,使用到了字符緩沖流BufferWriter.寫(xiě)入PrintStream流的數(shù)據(jù)怎么寫(xiě)到文件中.需要先了解一下數(shù)據(jù)讀取和寫(xiě)入的流程.
1.數(shù)據(jù)從流寫(xiě)到文件過(guò)程
輸出流----->緩沖流----->轉(zhuǎn)化流----->文件流------>文件.
2.數(shù)據(jù)從文件到流的過(guò)程
文件----->文件流----->轉(zhuǎn)化流----->緩沖流----->輸入流.
那么從PrintStream流寫(xiě)到文件的過(guò)程是:
PrintStream介紹
1.構(gòu)造方法
public PrintStream(OutputStream out) {} public PrintStream(OutputStream out, boolean autoFlush) {} public PrintStream(OutputStream out, boolean autoFlush, String encoding){} public PrintStream(String fileName) {} public PrintStream(String fileName, String csn){} public PrintStream(File file){} public PrintStream(File file, String csn){}- 創(chuàng)建了默認(rèn)編碼方式的PrintStream流,字節(jié)輸出流out作為PrintStream流的輸出流,不自動(dòng)刷新.
- 創(chuàng)建默認(rèn)編碼方式的PrintStream流,字節(jié)輸出流out作為PrintStream流的輸出流,傳入是否自動(dòng)刷新的參數(shù)autoFlush.
- 創(chuàng)建了指定編碼名稱encoding的PrintStream,字節(jié)輸出流out作為PrintStream流的輸出流.傳入是否自動(dòng)刷新的參數(shù)autoFlush.
- 創(chuàng)建了指定文件名稱,默認(rèn)字符編碼方式的PrintStream流,FileOutputStream流作為PrintStream流的輸出流.不自動(dòng)刷新.
- 創(chuàng)建指定了文件名稱和字符編碼名稱csn的PrintStream流,FileOutputStream作為PrintStream流的輸出流.不自動(dòng)刷新.
- 創(chuàng)建指定文件對(duì)象File和默認(rèn)編碼方式的PrintStream流,FileOutputStream作為PrintStream流的輸出流.不自動(dòng)刷新.
- 創(chuàng)建指定文件對(duì)象File和編碼名稱csn的PrintStream流,FileOutputStream作為PrintStream流的輸出流.不自動(dòng)刷新.
2.內(nèi)部變量
private final boolean autoFlush; private boolean trouble = false; private Formatter formatter; private BufferedWriter textOut; private OutputStreamWriter charOut;- autoFlush----是否自動(dòng)刷新緩沖區(qū).
- trouble----是否拋出異常的內(nèi)部標(biāo)識(shí).當(dāng)PrintStream流內(nèi)部拋出異常時(shí)會(huì)捕獲異常,然后將trouble的值設(shè)置成true.
- formatter----用于數(shù)據(jù)格式化的對(duì)象Formatter.
- textOut,charOut----PrintStream流本身不具備指定編碼功能,BufferedWriter提供了緩沖數(shù)據(jù)的功能,而OutputStreamWriter提供了按照指定編碼方法將字符轉(zhuǎn)化成字節(jié)的功能.
3.內(nèi)部方法.
public void flush() {} public void close() {} public boolean checkError(){} public void write(int b){} public void write(byte buf[], int off, int len){} public PrintStream printf(String format, Object ... args){} public PrintStream printf(Locale l, String format, Object ... args){} public PrintStream format(String format, Object ... args){} public PrintStream format(Locale l, String format, Object ... args){} public PrintStream append(CharSequence csq){} public PrintStream append(CharSequence csq, int start, int end){} public PrintStream append(char c){} public void print(boolean b){} public void print(char c) {} public void print(int i) {} public void print(long l) {} public void print(float f) {} public void print(double d) {} public void print(char s[]) {} public void print(String s) {} public void print(Object obj) {} public void println() {} public void println(boolean x) {} public void println(char x){} public void println(int x) {} public void println(long x) {} public void println(float x) {} public void println(double x) {} public void println(char x[]) {} public void println(String x) {} public void println(Object x) {}- flush()----刷新流,將緩沖的數(shù)據(jù)寫(xiě)到底層輸出流中.
- close()—關(guān)閉流,釋放關(guān)聯(lián)的資源.
- checkError()—檢查流中異常狀態(tài),如果PrintStream流中有異常拋出,返回true.
- write(int b)----將單個(gè)字節(jié)b寫(xiě)到PrintStream流中.
- write(byte buf[] ,int off,int len)----將字節(jié)數(shù)組buf中off位置開(kāi)始,len個(gè)字節(jié)寫(xiě)到PrintStream流中.
- printf(String format, Object … args)----將數(shù)據(jù)args按照默認(rèn)的Locale值和format格式進(jìn)行格式化后寫(xiě)到PrintStream流中,方法執(zhí)行等同于out.format(format, args)
- printf(Locale l, String format, Object … args)----將數(shù)據(jù)args根據(jù)Locale值和format格式進(jìn)行格式化后寫(xiě)到PrintStream輸出流中,方法執(zhí)行等同于out.printf(l, format,args).
- format(String format, Object … args)----根據(jù)默認(rèn)的Locale值和format格式來(lái)格式化數(shù)據(jù)args.
- format(Locale l, String format, Object … args)----將數(shù)據(jù)args根據(jù)Locale值和format格式進(jìn)行格式化.
- append(CharSequence csq, int start, int end)----將字符序列csq中start(包含)位置到end(不包含)之間的子字符序列添加到PrintStream輸出流中,此方法執(zhí)行等同于out.print(csq.subSequence(start, end).toString()).
- append(char c)----將單個(gè)字符添加到PrintStream輸出流中.此方法執(zhí)行等同于out.print?.
其他的print(Object obj)的重載方法與println(Object obj)的重載方法總結(jié)如下,兩個(gè)區(qū)別是println(Object obj)在寫(xiě)完數(shù)據(jù)后,會(huì)寫(xiě)入一個(gè)換行符.而這兩類方法寫(xiě)入數(shù)據(jù)時(shí)都會(huì)先將數(shù)據(jù)轉(zhuǎn)成字符串,然后調(diào)用底層輸出流寫(xiě)到文件中(比如boolean類型的數(shù)據(jù)true,會(huì)先轉(zhuǎn)成字符串"true").此兩類方法都將寫(xiě)入數(shù)據(jù)轉(zhuǎn)化成了字符串,所以實(shí)際調(diào)用的方法是write(String s).
| public | void print(boolean b){} | void println(boolean b){} | 將boolean類型數(shù)據(jù)對(duì)應(yīng)字符串寫(xiě)到PrintStream流中 |
| public | void print(char c){} | void println(char c){} | 將char類型數(shù)據(jù)對(duì)應(yīng)字符串寫(xiě)到PrintStream流中 |
| public | void print(int i) {} | void println(int i) {} | 將int類型數(shù)據(jù)對(duì)應(yīng)字符串寫(xiě)到PrintStream流中 |
| public | void print(long l) {} | void println(long l) {} | 將long類型數(shù)據(jù)對(duì)應(yīng)字符串寫(xiě)到PrintStream流中 |
| public | void print(float f) {} | void println(float f) {} | 將float類型數(shù)據(jù)對(duì)應(yīng)字符串寫(xiě)到PrintStream流中 |
| public | void print(double d) {} | void println(double d) {} | 將double類型數(shù)據(jù)對(duì)應(yīng)字符串寫(xiě)到PrintStream流中 |
| public | void print(char s[]) {} | void println(char s[]) {} | 將字符數(shù)組寫(xiě)到PrintStream流中 |
| public | void print(String s) {} | void println(String s) {} | 將字符串s寫(xiě)到PrintStream流中 |
| public | void print(Object obj) {} | void println(Object obj) {} | 將對(duì)象Obj對(duì)應(yīng)字符串寫(xiě)到PrintStream流中 |
| public | - | void println() {} | 將換行符寫(xiě)到PrintStream流中 |
PrintStream案例
public class PrintStreamDemo {public static void main(String[] args) throws IOException {final String fileName = "D:\\java.txt";File file = new File(fileName);testPrintMethod(fileName, file);testOtherMethod(fileName,file);}private static void testOtherMethod(String fileName,File file) throws IOException {PrintStream ps = new PrintStream(fileName);ps.write("helloworld".getBytes());ps.println();ps.format("文件名稱:%s", file.getName());ps.println();ps.write(0x41);ps.append("abcde");ps.close();}private static void testPrintMethod(final String fileName, File file) throws FileNotFoundException {PrintStream ps = new PrintStream(new FileOutputStream(fileName));ps.println('a');ps.println("hello");ps.println(2345);ps.print(3.1415);ps.println();//寫(xiě)入換行符.ps.printf("文件名稱:%s,是否可讀:%s", file.getName(),file.canRead());ps.println();ps.close();} }運(yùn)行結(jié)果:
testPrintMethod結(jié)果:
testOtherMethod的結(jié)果:
PrintStream源碼分析
public class PrintStream extends FilterOutputStream implements Appendable, Closeable {//是否自動(dòng)刷新緩沖區(qū).private final boolean autoFlush;//是否拋出異常的內(nèi)部標(biāo)識(shí).當(dāng)PrintStream流內(nèi)部拋出異常時(shí)會(huì)捕獲異常,然后將trouble的值設(shè)置成true.private boolean trouble = false;//用于數(shù)據(jù)格式化的對(duì)象Formatter.private Formatter formatter;//OutputStreamWriter轉(zhuǎn)化類,實(shí)現(xiàn)了編碼方式,將字符轉(zhuǎn)化字節(jié).//BufferWriter實(shí)現(xiàn)了數(shù)據(jù)的緩沖.//輸出流out是將內(nèi)存中數(shù)據(jù)寫(xiě)到文件中./** 所以三個(gè)流的轉(zhuǎn)化方式,將數(shù)據(jù)寫(xiě)到文件中的流程是:* 字符 緩沖 編碼成字節(jié) 字節(jié)* PrintStream---->BufferWriter--->OutputStreamWriter---->FileOutputStream---->文件.* */private BufferedWriter textOut;private OutputStreamWriter charOut;//判斷對(duì)象是否創(chuàng)建.private static <T> T requireNonNull(T obj, String message) {if (obj == null)throw new NullPointerException(message);return obj;}//根據(jù)字符編碼名稱返回Chatset對(duì)象.private static Charset toCharset(String csn)throws UnsupportedEncodingException{requireNonNull(csn, "charsetName");try {return Charset.forName(csn);} catch (IllegalCharsetNameException|UnsupportedCharsetException unused) {// UnsupportedEncodingException should be thrownthrow new UnsupportedEncodingException(csn);}}/*** 私有構(gòu)造方法,創(chuàng)建的編碼方式為charset的PrintStream,輸出流out作為PrintStream流的輸出流,* 傳入是否自動(dòng)刷新的參數(shù)autoFlush*/private PrintStream(boolean autoFlush, OutputStream out) {super(out);this.autoFlush = autoFlush;this.charOut = new OutputStreamWriter(this);this.textOut = new BufferedWriter(charOut);}private PrintStream(boolean autoFlush, OutputStream out, Charset charset) {super(out);this.autoFlush = autoFlush;this.charOut = new OutputStreamWriter(this, charset);this.textOut = new BufferedWriter(charOut);}private PrintStream(boolean autoFlush, Charset charset, OutputStream out)throws UnsupportedEncodingException{this(autoFlush, out, charset);}//創(chuàng)建了默認(rèn)編碼方式的PrintStream流,輸出流out作為PrintStream流的輸出流,不自動(dòng)刷新.public PrintStream(OutputStream out) {this(out, false);}//創(chuàng)建默認(rèn)編碼方式的PrintStream流,輸出流out作為PrintStream流的輸出流,傳入是否自動(dòng)刷新的參數(shù)autoFlush.public PrintStream(OutputStream out, boolean autoFlush) {this(autoFlush, requireNonNull(out, "Null output stream"));}//創(chuàng)建了指定編碼方式encoding的PrintStream,輸出流out作為PrintStream流的輸出流.傳入是否自動(dòng)刷新的參數(shù)autoFlush.public PrintStream(OutputStream out, boolean autoFlush, String encoding)throws UnsupportedEncodingException{this(autoFlush,requireNonNull(out, "Null output stream"),toCharset(encoding));}//創(chuàng)建了指定文件名稱,默認(rèn)字符編碼方式的PrintStream流,FileOutputStream流作為PrintStream流的輸出流.不自動(dòng)刷新public PrintStream(String fileName) throws FileNotFoundException {this(false, new FileOutputStream(fileName));}//創(chuàng)建指定了文件名稱和字符編碼名稱csn的PrintStream流,FileOutputStream作為PrintStream流的輸出流.不自動(dòng)刷新public PrintStream(String fileName, String csn)throws FileNotFoundException, UnsupportedEncodingException{this(false, toCharset(csn), new FileOutputStream(fileName));}//創(chuàng)建指定文件對(duì)象File和默認(rèn)編碼方式的PrintStream流,FileOutputStream作為PrintStream流的輸出流.不自動(dòng)刷新.public PrintStream(File file) throws FileNotFoundException {this(false, new FileOutputStream(file));}//創(chuàng)建指定文件對(duì)象File和編碼名稱csn的PrintStream流,FileOutputStream作為PrintStream流的輸出流.不自動(dòng)刷新.public PrintStream(File file, String csn)throws FileNotFoundException, UnsupportedEncodingException{// ensure charset is checked before the file is openedthis(false, toCharset(csn), new FileOutputStream(file));}//確保流沒(méi)有關(guān)閉.private void ensureOpen() throws IOException {if (out == null)throw new IOException("Stream closed");}//刷新流,調(diào)用flush()會(huì)將緩沖數(shù)據(jù)寫(xiě)到底層輸出流中.public void flush() {synchronized (this) {try {ensureOpen();out.flush();}catch (IOException x) {trouble = true;}}}private boolean closing = false; /* To avoid recursive closing *///關(guān)閉流,釋放關(guān)聯(lián)資源.public void close() {synchronized (this) {if (! closing) {closing = true;try {textOut.close();out.close();}catch (IOException x) {trouble = true;}textOut = null;charOut = null;out = null;}}}//刷新流,檢查異常狀態(tài),如果底層輸出流拋出異常,將會(huì)返回true.public boolean checkError() {if (out != null)flush();if (out instanceof java.io.PrintStream) {PrintStream ps = (PrintStream) out;return ps.checkError();}return trouble;}//設(shè)置流的異常狀態(tài).protected void setError() {trouble = true;}//清除流的異常狀態(tài)protected void clearError() {trouble = false;}//將單個(gè)字節(jié)b寫(xiě)到PrintStream流中.public void write(int b) {try {synchronized (this) {ensureOpen();out.write(b);if ((b == '\n') && autoFlush)out.flush();}}catch (InterruptedIOException x) {Thread.currentThread().interrupt();}catch (IOException x) {trouble = true;}}//將字節(jié)數(shù)組buf中off位置開(kāi)始,len個(gè)字節(jié)寫(xiě)到PrintStream流中.public void write(byte buf[], int off, int len) {try {synchronized (this) {ensureOpen();out.write(buf, off, len);if (autoFlush)out.flush();}}catch (InterruptedIOException x) {Thread.currentThread().interrupt();}catch (IOException x) {trouble = true;}}/**下面對(duì)于的字符操作的私有方法會(huì)時(shí)時(shí)刷新緩沖,保持跟底層輸出流一樣效率*///將字符數(shù)組buf寫(xiě)到PrintStream流中.private void write(char buf[]) {try {synchronized (this) {ensureOpen();textOut.write(buf);textOut.flushBuffer();charOut.flushBuffer();if (autoFlush) {for (int i = 0; i < buf.length; i++)if (buf[i] == '\n')out.flush();}}}catch (InterruptedIOException x) {Thread.currentThread().interrupt();}catch (IOException x) {trouble = true;}}//將字符串s寫(xiě)到PrintStream流中.private void write(String s) {try {synchronized (this) {ensureOpen();textOut.write(s);textOut.flushBuffer();charOut.flushBuffer();if (autoFlush && (s.indexOf('\n') >= 0))out.flush();}}catch (InterruptedIOException x) {Thread.currentThread().interrupt();}catch (IOException x) {trouble = true;}}//將換行符寫(xiě)到PrintStream流中private void newLine() {try {synchronized (this) {ensureOpen();textOut.newLine();textOut.flushBuffer();charOut.flushBuffer();if (autoFlush)out.flush();}}catch (InterruptedIOException x) {Thread.currentThread().interrupt();}catch (IOException x) {trouble = true;}}//將boolean類型數(shù)據(jù)對(duì)應(yīng)的字符串"true"或者"false"寫(xiě)到PrintStream流中,實(shí)際調(diào)用write()方法public void print(boolean b) {write(b ? "true" : "false");}//將char類型數(shù)據(jù)對(duì)應(yīng)字符串寫(xiě)到PrintStream流中,實(shí)際調(diào)用write()方法public void print(char c) {write(String.valueOf(c));}//將int類型數(shù)據(jù)對(duì)應(yīng)的字符串寫(xiě)到PrintStream流中,實(shí)際調(diào)用write()方法.public void print(int i) {write(String.valueOf(i));}//將long類型數(shù)據(jù)對(duì)應(yīng)的字符串寫(xiě)到PrintStream流中,實(shí)際調(diào)用write()方法.public void print(long l) {write(String.valueOf(l));}//將float類型數(shù)據(jù)對(duì)應(yīng)的字符串寫(xiě)到PrintStream流中,實(shí)際調(diào)用write()方法.public void print(float f) {write(String.valueOf(f));}//將doule類型數(shù)據(jù)對(duì)應(yīng)的字符串寫(xiě)到PrintStream流中,實(shí)際調(diào)用write()方法.public void print(double d) {write(String.valueOf(d));}//將字符數(shù)組寫(xiě)到PrintStream流中,實(shí)際調(diào)用write()方法.public void print(char s[]) {write(s);}//將字符串s寫(xiě)到PrintStream流中,s為null,將會(huì)寫(xiě)入"null",實(shí)際調(diào)用write()方法.public void print(String s) {if (s == null) {s = "null";}write(s);}//將對(duì)象obj對(duì)應(yīng)的字符串寫(xiě)到PrintStream流中,實(shí)際調(diào)用write()方法.public void print(Object obj) {write(String.valueOf(obj));}//將換行符寫(xiě)到PrintStream流中.用于終止當(dāng)前行(換行符由系統(tǒng)定義)public void println() {newLine();}//將boolean類型數(shù)據(jù)對(duì)應(yīng)的字符串+換行符寫(xiě)到PrintStream流中,實(shí)際調(diào)用print()-->write()public void println(boolean x) {synchronized (this) {print(x);newLine();}}//將char類型單個(gè)字符對(duì)應(yīng)字符串+換行符寫(xiě)到PrintStream流中,實(shí)際調(diào)用print()-->write()public void println(char x) {synchronized (this) {print(x);newLine();}}//將int類型數(shù)據(jù)對(duì)應(yīng)的字符串+換行符寫(xiě)到PrintStream流中,實(shí)際調(diào)用print()-->write()public void println(int x) {synchronized (this) {print(x);newLine();}}//將long類型數(shù)據(jù)對(duì)應(yīng)的字符串+換行符寫(xiě)到PrintStream流中,實(shí)際調(diào)用print()-->write()public void println(long x) {synchronized (this) {print(x);newLine();}}//將float類型數(shù)據(jù)對(duì)應(yīng)的字符串+換行符寫(xiě)到PrintStream流中,實(shí)際調(diào)用print()-->write()public void println(float x) {synchronized (this) {print(x);newLine();}}//將double類型數(shù)據(jù)對(duì)應(yīng)的字符串+換行符寫(xiě)到PrintStream流中,實(shí)際調(diào)用print()-->write()public void println(double x) {synchronized (this) {print(x);newLine();}}//將字符數(shù)組+換行符寫(xiě)到PrintStream流中,實(shí)際調(diào)用print()-->write()public void println(char x[]) {synchronized (this) {print(x);newLine();}}//將字符串+換行符寫(xiě)到PrintStream流中,實(shí)際調(diào)用print()-->write()public void println(String x) {synchronized (this) {print(x);newLine();}}//將對(duì)象x對(duì)應(yīng)的字符串+換行符寫(xiě)到PrintStream流中,實(shí)際調(diào)用print()-->write().public void println(Object x) {String s = String.valueOf(x);synchronized (this) {print(s);newLine();}}//將數(shù)據(jù)args按照默認(rèn)的Locale值和format格式進(jìn)行格式化后寫(xiě)到PrintStream流中.//方法執(zhí)行等同于out.format(format, args)public PrintStream printf(String format, Object ... args) {return format(format, args);}//將數(shù)據(jù)args根據(jù)Locale值和format格式進(jìn)行格式化后寫(xiě)到PrintStream輸出流中//方法執(zhí)行等同于out.printf(l, format,args)public PrintStream printf(Locale l, String format, Object ... args) {return format(l, format, args);}//根據(jù)默認(rèn)的Locale值和format格式來(lái)格式化數(shù)據(jù)args寫(xiě)到PrintStream輸出流中.public PrintStream format(String format, Object ... args) {try {synchronized (this) {ensureOpen();if ((formatter == null)|| (formatter.locale() != Locale.getDefault()))formatter = new Formatter((Appendable) this);formatter.format(Locale.getDefault(), format, args);}} catch (InterruptedIOException x) {Thread.currentThread().interrupt();} catch (IOException x) {trouble = true;}return this;}//將數(shù)據(jù)args根據(jù)Locale值和format格式進(jìn)行格式化后寫(xiě)到PrintStream輸出流中.public PrintStream format(Locale l, String format, Object ... args) {try {synchronized (this) {ensureOpen();if ((formatter == null)|| (formatter.locale() != l))formatter = new Formatter(this, l);formatter.format(l, format, args);}} catch (InterruptedIOException x) {Thread.currentThread().interrupt();} catch (IOException x) {trouble = true;}return this;}//將字符序列csq添加到PrintStream輸出流中,此方法執(zhí)行等同于 out.print(csq.toString())public PrintStream append(CharSequence csq) {if (csq == null)print("null");elseprint(csq.toString());return this;}//將字符序列csq中start(包含)位置到end(不包含)之間的子字符序列添加到PrintStream輸出流中//此方法執(zhí)行等同于out.print(csq.subSequence(start, end).toString())public PrintStream append(CharSequence csq, int start, int end) {CharSequence cs = (csq == null ? "null" : csq);write(cs.subSequence(start, end).toString());return this;}//將單個(gè)字符添加到PrintStream輸出流中.此方法執(zhí)行等同于out.print(c)public PrintStream append(char c) {print(c);return this;} }總結(jié)
PrintStream繼承自O(shè)utputStream,屬于字節(jié)流的一種,方法包含寫(xiě)入單個(gè)字節(jié)和字節(jié)數(shù)組的方法.相似流有PrintWriter,繼承自Writer()方法,屬于字符流的一種.PrintWriter流中沒(méi)有寫(xiě)入字節(jié)的方法,而有寫(xiě)入單個(gè)字符和字符數(shù)組的方法.
總結(jié)
以上是生活随笔為你收集整理的Java IO流之PrintStream分析的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: c#sort升序还是降序_被玩坏的数组排
- 下一篇: excelvba怎么设置不打开文件自动保