bytearraystreamdemo.java

来自「因此本系统的目标就是让顾客方便快捷和满意的购物。为了达到这一目标」· Java 代码 · 共 24 行

JAVA
24
字号
import java.io.*;
public class ByteArrayStreamDemo {
  public static void main(String args[]) throws Exception
   {     
	  String s = "hello world";
      byte [] b = s.getBytes();   
 	  ByteArrayInputStream bis = new ByteArrayInputStream(b); 
	  ByteArrayOutputStream bos = new ByteArrayOutputStream();
	  transform(bis,bos); 
//返回一个字节数组,并把字节数组中的所有数据转换成字符串输出
      System.out.println(bos.toString());  
      bis.close();
bos.close();
   }
   public static void transform(InputStream is, OutputStream os) throws Exception{
	   int ch;
	   while( ( ch =is.read() ) != -1 ){ //判断是否结束
int upperCh = (Character.toUpperCase((char)ch));  //字符包装类Character有一//个方法toUpperCase可以将字符变为大写,然后再用
//到强制类型转换
		   os.write(upperCh);
	   }
   }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?