您的位置:首页 > 职场人生

黑马程序员:将字符串的所有字符转化为大写(ByteArrayOutPutStream/ByteArrayInPutStream)

2011-07-11 10:54 375 查看
import java.io.*;
/**
*
*/
/**
* @author Administrator
*
*/
public class ByteArrayTest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String tem = "abcdefgh";
byte[] src = tem.getBytes();
ByteArrayInputStream in = new ByteArrayInputStream(src);
ByteArrayOutputStream out = new ByteArrayOutputStream();
transform(in, out);
byte[] result = out.toByteArray();
System.out.print(new String(result));
transform(System.in, System.out); // 键盘输入屏幕输出 ,ctrl+"z"结束键盘输入
}
public static void transform(InputStream in, OutputStream out) {

try {
int ch = in.read();
while (ch != -1) {
int reUpper = Character.toUpperCase((char) ch);
out.write(reUpper);
ch=in.read();
}
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐