public static void main(String[] a) throws IOException{ InputStream is = null; String s = " qwweabcdefgddklmnoprtqrstuvwyz 12345678fasdfadfadsfadfdafadf"; is = new ByteArrayInputStream(s.getBytes()); byte [] arry = new byte[8]; while(true) {
int value = is.read(); if(value >= 48&&value <=48+10) {
readlimit 参数告知此输入流在标记位置失效之前允许读取许多字节。 的常规协定是:如果方法 Supported 返回 true,则输入流总会在调用 之后记住所有读取的字节,并且无论何时调用方法 reset ,都会准备再次提供那些相同的字节。但是,如果在调用 reset 之前可以从流中读取多于 readlimit 的字节,则根本不需要该流记住任何数据。 InputStream 的 方法不执行任何操作。
参数:
readlimit - 在标记位置失效前可以读取字节的最大限制
InputStream is = null;
String s = " qwweabcdefgddklmnoprtqrstuvwyz 12345678fasdfadfadsfadfdafadf";
is = new ByteArrayInputStream(s.getBytes());
byte [] arry = new byte[8];
while(true)
{
int value = is.read();
if(value >= 48&&value <=48+10)
{
is.reset();
while(true){
value = is.read();
if(value >= 48&&value <=48+10)
{
arry[0] = (byte)value;
break;
}
}
break;
}
is.(8);
is.skip(7);
}
is.read(arry, 1, 7);
System.out.println(new String(arry));
}类似的举个例子,用 reset skip 查找流 中的 数字串
这个地方写错了,应该是
if(value >= 48&&value <48+10)