【发布时间】:2012-02-03 19:58:39
【问题描述】:
我正在从 Java 学习 java:完整参考。 我目前正在研究本章中的示例:输入/输出:探索 java.io 我从下面的示例中理解了几行代码。 谁能帮我举个例子。
import java.io.*;
class FileInputStreamDemo
{
public static void main(String args[]) throws IOException
{
InputStream f = new FileInputStream("E://SomeRandomTextFile.txt");
System.out.println("Total available bytes : " + size = f.available());
int n = size/40;
System.out.println("First" + n + " bytes of file one read() at a time");
for(int i=0; i<n; i++)
{
System.out.println((char) f.read());
}
System.out.println("\n Still available: "+ f.available());
System.out.println("Reading the text " + n + " with one read(b[])");
byte b[] = new byte[n];
if(f.read(b) != n)
{
System.err.println("coudn't read" + n + "bytes.");
}
System.out.println(new String(b,0,n));
}
在上面的代码中,我勉强看懂了最后五行代码。
结果是什么
f.read(b)
什么是
System.err
和
结果是什么
new String(b,0,n);
【问题讨论】: