您好,登錄后才能下訂單哦!
創(chuàng)建源:字節(jié)數(shù)組 不要太大
選擇流: InputStream is =new ByteArrayInputStream(byte[] byte);
操作(輸入)
無釋放資源(使用.close()會是一個空方法,為了保證風(fēng)格統(tǒng)一)
源頭由文件(硬盤)換成字節(jié)數(shù)組:
因為字符數(shù)組是內(nèi)存而不是文件(硬盤),所以java虛擬機(jī)可直接調(diào)用,由垃圾回收機(jī)制
(gc)來釋放,所以無需手動.close()釋放
public class test{
public static void main(String[]args)
{
//創(chuàng)建源
byte[] src="ad ad and".getBytes();
//選擇流
InputStream is=null;
try {
is=new ByteArrayInputStream(src);
byte[] flush=new byte[5]; //緩沖字符器
int len=-1;
while((len=is.read(flush))!=-1)
{
String s=new String(flush,0,len); //解碼,有字節(jié)到字符串
System.out.println(s);
}
}catch(IOException e)
{
e.printStackTrace();
}
}
}
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。