JavaIO流学习总结-StringReader和StringWriter基本操作练习
作者:互联网
package io;
import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter; /*
* 修改日期:2020/04/05
* 修改人:牟松
* 字符流StringReader和StringWriter基本操作练习
*/
public class ceshi {
public static void main(String[] args)
{
//用法跟byteArrayInputStream和byteArrayOutputStream的用法差不多
StringReader reader = new StringReader("i love you");
StringWriter writer = new StringWriter();
int length;
try {
while((length = reader.read())!=-1)
{
int chUpper = Character.toUpperCase(length);
writer.write(chUpper);
}
System.out.println(writer.getBuffer().toString());
} catch (IOException e) {
e.printStackTrace();
}
}
}
import java.io.StringReader;
import java.io.StringWriter; /*
* 修改日期:2020/04/05
* 修改人:牟松
* 字符流StringReader和StringWriter基本操作练习
*/
public class ceshi {
public static void main(String[] args)
{
//用法跟byteArrayInputStream和byteArrayOutputStream的用法差不多
StringReader reader = new StringReader("i love you");
StringWriter writer = new StringWriter();
int length;
try {
while((length = reader.read())!=-1)
{
int chUpper = Character.toUpperCase(length);
writer.write(chUpper);
}
System.out.println(writer.getBuffer().toString());
} catch (IOException e) {
e.printStackTrace();
}
}
}
标签:java,StringReader,writer,StringWriter,length,io,基本操作 来源: https://www.cnblogs.com/musong1998/p/12637533.html