StringReader是装饰Reader的类,其用法是读取一个String字符串
package com.itbuluoge.test;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.StringReader;
public class StringInputFile {
public static String read(String content) throws Exception
{
StringReader in=new StringReader(content);
int s;
String sb = "";
while((s=in.read())!=-1)
{
sb+=(char)s;
}
in.close();
return sb;
}
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
System.out.println(read("我是蒋辉文!你是谁呢?"));
}
}
我们可以看到,会将我们的String流返回输出。