黑马程序员:将字符串的所有字符转化为大写(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();
}
}
}
/**
*
*/
/**
* @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();
}
}
}
相关文章推荐
- 黑马程序员:数组及字符串IO流:ByteArrayInputStream、CharArrayReader、StringReader等
- 把字符串的所有字符转化为大写
- 黑马程序员_java_IO流_FileInputStream_FileOutputStream_File_递归_Properties_ByteArrayInputStream_ByteArrayOut
- 104.把字符串奇数位上的小写字母转化为大写且其他字符不变
- 将数组转化为字符串,并用指定字符分隔(Array&ArrayList)
- 十六进制字符串 与 所有字符(中文)之间的相互转化
- ByteArrayInputStream和ByteArrayOutputStream使用-黑马程序员
- 汇编程序:将字符串中所有大写字符转为小写
- 黑马程序员-学习日志-ByteArrayInputStream
- Java IO深入理解字节和字符数组(ByteArrayInputStream、ByteArrayOutputStream、CharArrayReader、CharArrayWriter)
- 把字符串的所有字符转化为小写
- 字符串相互转字符数组 string byte 数组 array of byte
- c语言从键盘中输入一串字符串,将字符中的大写转化成小写字母,将小写字母转换成大写字母,以*号键结束
- 黑马程序员——Java IO—字节流—ByteArrayInputStream和ByteArrayOutputStream
- java 将short,int,string转化成bytearray用socket发送
- ByteArrayOutputStream 和 ByteArrayInputStream的说明
- 请实现一个算法,确定一个字符串的所有字符是否全都不同。这里我们要求不允许使用额外的存储结构。
- C/C++ 各种字符编码字符串的转换 可用于XML文件的字符转化读写 (收集 GBK - UTF8 - Unicode - ANSI )
- 给出一个set的字符和一个正数k,求所有由这个set能组成长度为k的字符串集合 print-all-combinations-of-given-length
- 把字符串转化为字符数组