- 論壇徽章:
- 0
|
I/O Streams 的典型應(yīng)用
一.input streams:
1.buffered input file:
BufferedReader in = new BufferedReader(new FileReader("fileName" or instance of File));
常用于行讀入操作。
2.input from memory:
StringReader in2 = new StringReader(s2); s2:String 類的實例。這樣就可以
一個一個地讀入s2中的字符。
3.Formatted memory input
DataInputStream in = new DataInputStream(inputStream及其子類的實例)。
使用readType方法讀入要求的數(shù)據(jù)類型。
4.Fileout:
PrintWriter out1 = new PrintWriter(new BufferedWriter(new FileWriter("filename",or instance of File)));
5.Reading from standard input:
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
二. output stream:
1.PrintWriter格式化的輸出是可以直接閱讀的。
2。Reading and writing random access files:
RandomAccessFile raf = new RandomAcessFile("filename",mode),mode:為打開方式可以為
r,rw,rws,rwd;
3.changing System.out to a printWriter:
PrintWriter out = new PrintWriter(System.out, true);
true用來開啟自動flush();
本文來自ChinaUnix博客,如果查看原文請點:http://blog.chinaunix.net/u/28187/showart_259184.html |
|