正在加载图片...
jay impor java. io class Count Bytes( .a public static void main(Stringll args)throws IOException Inputstream in 以指定文件数据 try 作为数据流 in=new FileInputStream(args[0D; int total=0; 计算输入数 whie( inread0=1)+据的字节数 total++ 出除 System. out. printIn( totah“ bytes”); 3 finally if(in=null) 关闭已打开 try in close; 的输入流 用 catch(IOException e C用java.io.InputStream Class • 当创建InputStream类对象时,便自动打开 了对象所表示的输入流 • InputStream所有与输入相关的方法声明抛 出异常类IOException • InputStream类的对象在完成数据输入后, 除标准输入流类对象System.in外,必须调用 close方法关闭输入流,通常可将该方法的调 用放入finally语句块中 import java.io.*; class CountBytes{ public static void main(String[] args) throws IOException{ InputStream in; try{ in=new FileInputStream(args[0]); int total=0; while(in.read()!=-1) total++; System.out.println(total+“ bytes”); } finally{ if(in!=null) try{ in.close(); } catch(IOException e){ } } } } 以指定文件数据 作为数据流 计算输入数 据的字节数 关闭已打开 的输入流
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有