package cn.itcast.io.p6.bytestream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
public class ByteArrayStreamDemo {
/**
* @param args
* @throws IOException
* 特點
* 1.記憶體操作流
* 2.不操作底層資源,不調用作業系統的底層資源,操作記憶體中的資料,記憶體流不需要關閉
* 3.關閉流後還可以使用
* 本例:記憶體操作流完成的一個大小寫字母轉換的程式:
*/
public static void main(String[] args) {
String str = "HELLO WORLD!";
ByteArrayInputStream bis = new ByteArrayInputStream(str.getBytes());//将内容輸入到記憶體中
ByteArrayOutputStream bos = new ByteArrayOutputStream();//将記憶體中的資料輸出
int ch = 0;
bis.skip(2);//跳過兩個位元組
System.out.println(bis.available());//傳回此輸入流讀取的(或跳過)剩餘的位元組數
while((ch=bis.read())!=-1){
bos.write(Character.toLowerCase(ch));//将大小字元轉化成小寫
}
System.out.println(bos.toString());
}
}
Face your past without regret. Handle your present with confidence.Prepare for future without fear. keep the faith and drop the fear.
面對過去無怨無悔,把握現在充滿信心,備戰未來無所畏懼。保持信念,克服恐懼!一點一滴的積累,一點一滴的沉澱,學技術需要不斷的積澱!