java的基本输入流类是java.io.InputStream
public abstract class InputStream{
public abstract int read() throws IOException;
public int read(byte[] input){} throws IOException
public int read(byte[] input,int offset,int length){} throws IOException
public long skip(long n){} throws IOException
public int available(){} throws IOException
public void close(){} throws IOEXception
}
InputStream的基本方法是没有参数的read()方法。这个方法从输入流的源中读取1字节数据,作为一个0到255的int返回。流的结束通过返回-1来表示。read方法会等待并阻塞其后任何代码的执行,直到有1字节的数据可供读取。
输入和输出可能很慢,所以如果程序在做其他的重要工作,要尽量将I/O放到单独的线程中。
可以通过设置socketTimeOut属性来抛出当read超时时的错误。