用ByteArrayIn/OutputStream内存流大写字符串转小写
来源:互联网 发布:网络保险平台排名 编辑:程序博客网 时间:2024/05/21 19:40
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
/**
* 大写字符串用内存流转小写的两种方法
* @author ddmcc
*
*/
public class ByteArrayTest{
public static void main(String[] args) throws IOException{
test1();
}
public static void test1() throws IOException{
}
}
System.out.println(dos.toString()); //得到字符串
dos.close();
dis.close();
}
}
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
/**
* 大写字符串用内存流转小写的两种方法
* @author ddmcc
*
*/
public class ByteArrayTest{
public static void main(String[] args) throws IOException{
test1();
}
public static void test1() throws IOException{
String str = "ABCDEF";
ByteArrayOutputStream daos = new ByteArrayOutputStream(); //创建输出流
DataOutputStream dops = new DataOutputStream(daos); //创建输出数据流
dops.writeUTF(str.toLowerCase());//写入变成小写后的字符串
ByteArrayInputStream dais = new ByteArrayInputStream(daos.toByteArray()); //把输出流字节数组当成数据源
DataInputStream dips = new DataInputStream(dais);//输入数据流
System.out.println(dips.readUTF());//读取数组内容
dips.close();
dops.close();}
public static void test2() throws IOException{
String str = "ABCDEF";
ByteArrayInputStream dis = new ByteArrayInputStream(str.getBytes()); //字符串转成字节数组
ByteArrayOutputStream dos = new ByteArrayOutputStream();
int len = 0;while((len = dis.read()) != -1){ //读取数组中内容
char ch = (char)len; //int数据转成char
dos.write(Character.toLowerCase(ch)); //写入转成小写的字符}
System.out.println(dos.toString()); //得到字符串
dos.close();
dis.close();
}
}
阅读全文
0 0
- 用ByteArrayIn/OutputStream内存流大写字符串转小写
- 字符串大写转小写
- iOS 字符串小写转大写
- 汇编-字符串小写转大写
- [Java] java字符串大写转小写,小写转大写
- java字符串大写转小写,小写转大写
- java字符串大写转小写,小写转大写
- java字符串大写转小写,小写转大写
- java字符串大写转小写,小写转大写
- java 一字符串中 大写转小写、小写转大写
- C风格字符串大写转小写
- java 字符串首字母小写转大写
- 小写转大写金额
- 数字小写转大写
- 小写转大写
- 数字小写转大写
- 人民币小写转大写
- 金额小写转大写
- Codeforces Round #245 (Div. 1) ABCDE
- Android启动界面先白屏或者黑屏然后才出现画面的解决办法
- c++日志类实现
- Run through the rain
- 从源文件到可执行文件
- 用ByteArrayIn/OutputStream内存流大写字符串转小写
- Java中静态方法与非静态方法的区别
- 关于Log4j的总结
- JavaWeb面试题
- 三子棋
- 反向传播算法详细计算过程与结论公式
- 关于微信的一些总结(一天进步一点,坚持不懈,成功会慢慢向你走进)
- IDEA scala中的 java版本 警告
- 文章标题