首页 > 基础教程 > IO流 > InputStream类
Java InputStream.reset()重新定位输入流的位置
定义
public void reset()
返回
不返回任何值。
异常
IOException:I/O 错误
实例
public static void main(String[] args) throws Exception
{
InputStream is = null;
try
{
is = new FileInputStream("C://51gjie.txt");
System.out.println("第一个字符:"(char) is.read());
is.mark(0);
System.out.println("mark后的字符:"+(char) is.read());
if(is.markSupported())
{
is.reset();
System.out.println("重置流位置");
System.out.println("reset重置后新的字符:"+(char) is.read());
}
else
{
System.out.print("InputStream不支持reset()");
}
}
catch(Exception e)
{
}
finally
{
if(is != null) is.close();
}
}
InputStream.reset()必须先调用mark()方法标识了流的位置,并且调用markSupported返回true,这个时候才能生效。
版权声明:本文为JAVASCHOOL原创文章,未经本站允许不得转载。