内存操作流
可以將輸出的位置設置在內存上,此時就要使用ByteArrayInputStream、ByteArrayOutputStream來完成輸入和輸出功能。
ByteArrayInputStream主要完成將內容寫入到內存中
ByteArrayOutputStream的功能主要是將內存中的數據輸出
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 自動生成的方法存根String str = "HELLOWORD";ByteArrayInputStream bis = null; //聲明一個內存的輸入流ByteArrayOutputStream bos = null; //聲明一個內存的輸出流bis = new ByteArrayInputStream(str.getBytes()); //向內存中輸入內容bos = new ByteArrayOutputStream(); //準備從ByteArrayInputStream中讀數據int temp = 0;while((temp=bis.read()) != -1){char c = (char)temp; //將讀取的數字變為字符bos.write(Character.toLowerCase(c)); //將字符變為小寫}String newStr = bos.toString(); //取出內容try{bis.close();bos.close();}catch(IOException e){e.printStackTrace();}System.out.println(newStr);}}?
轉載于:https://www.cnblogs.com/tonglin0325/p/5277090.html
總結
- 上一篇: 做梦梦到狼攻击什么意思
- 下一篇: 梦到病人康复了是啥意思