IO之字节数组输入输出流
2010-01-19 02:34
323 查看
package joeho.net.csdn.blog.io;
import java.io.*;
public class ByteArrayTest {
/**
* Method main
*
*
* @param args
*
*/
public static void main(String[] args) {
String strData = "afaerttwertrwert";
byte[] buf = strData.getBytes();
ByteArrayInputStream in = new ByteArrayInputStream(buf);
ByteArrayOutputStream out = new ByteArrayOutputStream();
upperTransform(in,out);
System.out.println(new String(out.toByteArray()));
//从键盘接受数据,用CTRL+Z退出
upperTransform(System.in,System.out);
}
/**
* Method upperTransform
*
*
* @param in
* @param out
*
*/
public static void upperTransform(InputStream in, OutputStream out) {
// TODO: Add your code here
int ch=0;
try{
while((ch=in.read())!=-1){
ch = Character.toUpperCase(ch);
out.write(ch);
}
}catch(Exception e){e.printStackTrace();}
}
}
import java.io.*;
public class ByteArrayTest {
/**
* Method main
*
*
* @param args
*
*/
public static void main(String[] args) {
String strData = "afaerttwertrwert";
byte[] buf = strData.getBytes();
ByteArrayInputStream in = new ByteArrayInputStream(buf);
ByteArrayOutputStream out = new ByteArrayOutputStream();
upperTransform(in,out);
System.out.println(new String(out.toByteArray()));
//从键盘接受数据,用CTRL+Z退出
upperTransform(System.in,System.out);
}
/**
* Method upperTransform
*
*
* @param in
* @param out
*
*/
public static void upperTransform(InputStream in, OutputStream out) {
// TODO: Add your code here
int ch=0;
try{
while((ch=in.read())!=-1){
ch = Character.toUpperCase(ch);
out.write(ch);
}
}catch(Exception e){e.printStackTrace();}
}
}
相关文章推荐
- 黑马程序员————java基础---------IO输入输出之字节流
- Java IO深入理解字节和字符数组(ByteArrayInputStream、ByteArrayOutputStream、CharArrayReader、CharArrayWriter)
- 第7讲 IO/输入与输出-字节字符输入输出流类
- IO(输入输出)(一)字节流
- JAVA IO分析二:字节数组流、基本数据&对象类型的数据流、打印流
- java IO总结之字节流操作控制台输入输出(高效)
- 字节数组输入输出流
- 黑马程序员_<<IO扩展对象和编码(序列化,管道流,字节(符)数组),随机访问文件>>
- 黑马程序员-----IO之字节数组流、字符数组流和字符串流
- 黑马程序员--读写字节数组,随机读写流,集合IO的思维导图,多线程部分,单例设计模式,线程和进程的概念,Java中的线程的创建方式,线程的随机性,线程的状态图,多线程操作共享数据的安全性,死锁
- 黑马程序员_<<IO扩展对象和编码(序列化,管道流,字节(符)数组),随机访问文件>>
- Java IO学习--(五)字节和字符数组
- IO输入输出流
- C# 中字符串string和字节数组byte[]的转换
- Python学习笔记015——序列(字节数组 bytearray)
- Java IO之字节流
- Java_语法基础_字节数组转换为16进制字符串
- 简单的输入输出、一维数组、二维数组、普通遍历、使用foreach语句遍历数组操作
- 『0013』 - Solidity Types - 固定大小字节数组(Fixed-size byte arrays)
- [Java] 从图片URL中读取字节数组