都说读读文件之后要调用close()方法,否则输入流一直开着就会占用内存,但是在eclipse中运行程序之后,输入流难道没有自动关闭吗?运行程序之后,红色的小按钮自动变成暗红色了,这不是关闭的意思吗?再问个问题,运行完程序之后虚拟机有没有关闭?
public class FileInputStreamTest
{
public static void main(String[] args)throws Exception
{
InputStream is=new FileInputStream("weiwei.txt");
byte[] b=new byte[200];
int length=0;
while(-1!=(length=is.read(b,0,100)))
{
String str=new String(b,0,length);
System.out.println(str);
}
//is.close();
}
}
public class FileInputStreamTest
{
public static void main(String[] args)throws Exception
{
InputStream is=new FileInputStream("weiwei.txt");
byte[] b=new byte[200];
int length=0;
while(-1!=(length=is.read(b,0,100)))
{
String str=new String(b,0,length);
System.out.println(str);
}
//is.close();
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货