看看这个代码能不能满足你的需求- import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.IOException;
- import java.io.OutputStreamWriter;
- import java.io.StringReader;
- public class IODemo {
- public static void main(String[] args) throws IOException {
-
- String str = "Nice to meet you.";
- StringReader reader = new StringReader(str);
- BufferedReader bufr = new BufferedReader(reader);
- BufferedWriter bufw = new BufferedWriter(new OutputStreamWriter(
- System.out));
- String line = null;
- while ((line = bufr.readLine()) != null) {
- bufw.write(line);
- }
- // 因为是缓冲输出流,所以需要刷新,不然没有结果
- bufw.flush();
- }
- }
复制代码 |