日期:2014-05-20 浏览次数:20790 次
package day1; import java.io.ByteArrayInputStream; import java.io.IOException; public class ByteArrayTester { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub byte[] buff=new byte[]{2,15,67,-1,-9,9}; ByteArrayInputStream in=new ByteArrayInputStream(buff,1,4); int data=in.read(); while(data!=-1){ System.out.println(data+" "); data=in.read(); } try { in.close();//[color=#FF0000]ByteArrayInputStream的close()方法实际上不执行任何操作,那为什么要写呢? 还有in对象应该没有销毁吧,个人认为应该加上 in=null;[/color] } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
/** * Closing a <tt>ByteArrayInputStream</tt> has no effect. The methods in * this class can be called after the stream has been closed without * generating an <tt>IOException</tt>. * <p> */ public void close() throws IOException { }
------解决方案--------------------
在写数据库程序的时,都有像in=null的语句,好让垃圾收集器把它回收,可能在这里写一下会好一些吧。