package cn.webmctv.test;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
public class TestInputStream {
public static void main(String[] args) {
/* 為什么要關(guān)閉和io流, 由于java底層是用c實(shí)現(xiàn)的, 所以當(dāng)我們不停的調(diào)用new InputStream -> impl
* 時(shí)候, c打開(kāi)的文件會(huì)一直沒(méi)有關(guān)閉,而導(dǎo)致文件刪除不了,別的程序訪問(wèn)不了的問(wèn)題,和操作系統(tǒng)打開(kāi)文件
* 超過(guò)最大數(shù)異常。而下面new FileInputStream(new File("c:/q.txt"));這種方式?jīng)]有關(guān)閉c打開(kāi)的
* 文件一直new 就會(huì)出現(xiàn)打開(kāi)文件太多異常。
short count = 0;
InputStream inStream = null;
try {
for (int i = 0; i < Short.MAX_VALUE; i++) {
//inStream.
inStream = new FileInputStream(new File("/root/install.log"));
//count ++;
System.out.println("count: " + count++);
}
//p.load(inStream);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally{
if(inStream != null) try{ inStream.close(); } catch(IOException e){};
}
System.out.println(Short.MAX_VALUE);
*/
short count = 0;
InputStream inStream = null;
for (int i = 0; i < Short.MAX_VALUE; i++) {
try {
//inStream.
inStream = new FileInputStream(new File("/root/install.log"));
//count ++;
System.out.println("count: " + count++);
//p.load(inStream);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally{
if(inStream != null) try{ inStream.close(); } catch(IOException e){};
}
}
System.out.println(Short.MAX_VALUE);
}
}