zoukankan      html  css  js  c++  java
  • ByteArrayInputStream和ByteArrayOutputStream向内存中读写数据

    import java.io.*;
    public class ByteArrayDemo
    {
    	public static void main(String[] args) 
    	{
    		String str="HELLOWORD";
    		ByteArrayInputStream bis = null;
    		ByteArrayOutputStream bos = null;
    		bis=new ByteArrayInputStream(str.getBytes());
    		bos=new ByteArrayOutputStream();
    		int temp=0;
    		while((temp=bis.read())!=-1){
    			char c=(char)temp;          ///读入的数字转换为字符串
    			bos.write(Character.toLowerCase(c));           ///字符串小写
    		}
    		///所有数据都存在ByteArrayOutputStream中了
    		String newStr=bos.toString();       ///读取内容
    		try{
    			bis.close();
    			bos.close();
    		}catch(IOException e){
    			e.printStackTrace();
    		}
    		System.out.println(newStr);
    	}
    }

  • 相关阅读:
    制作文件的备份
    文件的读写
    文件的打开与关闭
    文件操作介绍
    数据类型转换
    位运算
    进制
    函数使用注意事项
    匿名函数
     递归函数
  • 原文地址:https://www.cnblogs.com/dengshiwei/p/4258647.html
Copyright © 2011-2022 走看看