内存操作流
可以將輸出的位置設(shè)置在內(nèi)存上,此時(shí)就要使用ByteArrayInputStream、ByteArrayOutputStream來(lái)完成輸入和輸出功能。
ByteArrayInputStream主要完成將內(nèi)容寫入到內(nèi)存中
ByteArrayOutputStream的功能主要是將內(nèi)存中的數(shù)據(jù)輸出
import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException;//================================================= // File Name : ByteArrayStream_demo //------------------------------------------------------------------------------ // Author : Common//主類 //Function : ByteArrayStream_demo public class ByteArrayStream_demo {public static void main(String[] args) {// TODO 自動(dòng)生成的方法存根String str = "HELLOWORD";ByteArrayInputStream bis = null; //聲明一個(gè)內(nèi)存的輸入流ByteArrayOutputStream bos = null; //聲明一個(gè)內(nèi)存的輸出流bis = new ByteArrayInputStream(str.getBytes()); //向內(nèi)存中輸入內(nèi)容bos = new ByteArrayOutputStream(); //準(zhǔn)備從ByteArrayInputStream中讀數(shù)據(jù)int temp = 0;while((temp=bis.read()) != -1){char c = (char)temp; //將讀取的數(shù)字變?yōu)樽址鸼os.write(Character.toLowerCase(c)); //將字符變?yōu)樾憓String newStr = bos.toString(); //取出內(nèi)容try{bis.close();bos.close();}catch(IOException e){e.printStackTrace();}System.out.println(newStr);}}?
轉(zhuǎn)載于:https://www.cnblogs.com/tonglin0325/p/5277090.html
總結(jié)
- 上一篇: 做梦梦到狼攻击什么意思
- 下一篇: java分页数据导出excel