package three.day.io;
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.IOException;
public class StandardIODemo02
{
public static void main(String[] args)
{
int count;
String str;
byte[] b = new byte[256];
DataInputStream din = new DataInputStream(System.in);
BufferedInputStream bin = new BufferedInputStream(din);
try
{
if(bin.markSupported())
{
System.out.println("支持mark");
System.out.println("输入字符串,按Enter键结束");
count = bin.read(b);
bin.mark(256);
System.out.println("读入字节数:"+count);
str = new String(b,0,count);
System.out.println("字符串的长度是:"+str.length());
System.out.println("你输入的字符串是:"+str);
bin.reset();
System.out.println("重置后字节数:"+count);
count = bin.read(b);
str = new String(b,0,2);
System.out.println("字符串的前两个:"+str);
System.out.println("重输入后字节数:"+count);
bin.reset();
bin.skip(count/2);
}
else
{
}
din.close();
bin.close();
}
catch(IOException e)
{
e.printStackTrace();
}
}
}
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.IOException;
public class StandardIODemo02
{
public static void main(String[] args)
{
int count;
String str;
byte[] b = new byte[256];
DataInputStream din = new DataInputStream(System.in);
BufferedInputStream bin = new BufferedInputStream(din);
try
{
if(bin.markSupported())
{
System.out.println("支持mark");
System.out.println("输入字符串,按Enter键结束");
count = bin.read(b);
bin.mark(256);
System.out.println("读入字节数:"+count);
str = new String(b,0,count);
System.out.println("字符串的长度是:"+str.length());
System.out.println("你输入的字符串是:"+str);
bin.reset();
System.out.println("重置后字节数:"+count);
count = bin.read(b);
str = new String(b,0,2);
System.out.println("字符串的前两个:"+str);
System.out.println("重输入后字节数:"+count);
bin.reset();
bin.skip(count/2);
}
else
{
}
din.close();
bin.close();
}
catch(IOException e)
{
e.printStackTrace();
}
}
}