我写了一段代码,里面有Mark()方法,其中的参数不起作用这是为什么啊??
import java.io.*;public class TestBufferedInputStream{
public static void main(String args[]){
try{
BufferedInputStream bis = new BufferedInputStream(new FileInputStream("TestBufferedInputStream.java"));
int c = 0;
bis.read();
bis.read();
bis.(100);
for(int i = 0;i<110&&(c = bis.read()) != -1;i++){
System.out.print((char)c);
} System.out.println();
bis.reset();
for(int i = 0;i<10&&(c = bis.read()) != -1;i++){
System.out.print((char)c);
} bis.close();
}catch(IOException e){
e.printStackTrace();
}
}
}

解决方案 »

  1.   

    for(int i = 0;i<110&&(c = bis.read()) != -1;i++){
    貌似是:
    for(int i = 0;i<10&&(c = bis.read()) != -1;i++){
    这一句表示:
    bis.(100);
    极限是100个字符以内有效,110就超出范围了
      

  2.   

    看看源码你就知道它是干嘛的了 (int limit)
    /**
         * The maximum read ahead allowed after a call to the 
         * <code></code> method before subsequent calls to the 
         * <code>reset</code> method fail. 
         * Whenever the difference between <code>pos</code>
         * and <code>pos</code> exceeds <code>limit</code>,
         * then the   may be dropped by setting
         * <code>pos</code> to <code>-1</code>.
         *
         * @see     java.io.BufferedInputStream#(int)
         * @see     java.io.BufferedInputStream#reset()
         */
     protected int limit;
      

  3.   

    你先定义了那个缓冲字节流 bis ,然后就要读取bis 里的东西了吧? 
    然后你定义了一个,这个在Api上的意思说的是:在此输入流中标记当前的位置。说通俗一点吧,就是对BufferedInputStream bis 进行了标记,记录它在接下来从第100个字节开始读取。
    那个后面的reset()方法,就是让读取的数据重新回到的那第100个字节的位置,重新往后读取。
      

  4.   


    不是的我是想看看方法的效果和当读取范围超过限制时失效,可是当超出范围后依然能够reset到原标记位
      

  5.   

    印象中好像在哪个贴子上说方法对FileInputStream不起作用,求签定...
      

  6.   

    这个要看具体实现的,比如
    你用 ByteArrayInputStream 做输入流,那么只要你了,哪怕你只了1,你读取几M都可以reset回来(如果你的原始ByteArrayInputStream里确实有这么多内容的话)
      

  7.   

    具体看源码里是否实现了  方法及具体实现细节1.ByteArrayInputStream
      
        public void (int readAheadLimit) {
     = pos;
        }
      
      与方法参数无关。只要你了,就可以reset.而不管你往后读取了多少个.2.BufferedInputStream
      
       public synchronized void (int readlimit) {
    limit = readlimit;
    pos = pos;
       }
      
      看代码,似乎是和readlimit参数有关。但是仔细查看相关代码,可知,BufferedInputStream默认开8k的缓冲区,如果你在开始就,那么理论上最长可以read 8k数据,还可以成功reset回来。  InputStream方法里关于的文档,仅仅是一个最低实现要求。也就是说,如果支持,那么当你读取不超过readlimit个字节时,reset必须还原至的点。但是如果你有能力缓冲更多,则没有要求,也就是说,并没有强制要求读取超过readlimit时必须失效
      

  8.   


    签定失败
    public class TestBufferedInputStream {
    public static void main(String args[]) {
    try {
    int c = 0;
    byte [] bytes = new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
    BufferedInputStream bis = new BufferedInputStream(bais);
    bis.read();
    bis.(3);
    for(int i = 0;i<6&&(c = bis.read()) != -1;i++){
    System.out.print(c);
    }
    System.out.println();
    bis.reset();
    for(int i = 0;i<6&&(c = bis.read()) != -1;i++){
    System.out.print(c);
    }
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    }
    结果:
    234567
    234567
      

  9.   

    对于 FileInputStream.无实现,即继承了InputStream的缺省实现。不支持,自然方法里的参数也无关痛痒