import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.FileInputStream;public class chinese_english_inputstream {
public static void main(String[] args) throws Exception {
FileInputStream fis = new FileInputStream("e:/io流专用文件/da1.txt");
BufferedInputStream bis = new BufferedInputStream(fis);
byte[] b = new byte[8];
bis.read(b);
ByteArrayInputStream fais = new ByteArrayInputStream(b);
fais.(1);      //这里不管是几 控制台输出的都是第一个字符.
fais.reset();
System.out.println((char)fais.read());
}
}这个也一样import java.io.BufferedInputStream;
import java.io.FileInputStream;public class chinese_english_inputstream {
public static void main(String[] args) throws Exception {
FileInputStream fis = new FileInputStream("e:/io流专用文件/da1.txt");
BufferedInputStream bis = new BufferedInputStream(fis);
bis.(5);
bis.reset();
System.out.println((char)bis.read());
}
}
《da1.txt》:
ab中国人求解啊

解决方案 »

  1.   

    Seems your understanding of () method is incorrect. In fact stream s are intended to be used in situations where you need to read ahead a little to see what’s in the stream.() method s the current position in this input stream. A subsequent call to the reset method repositions this stream at the last ed position so that subsequent reads re-read the same bytes.I think you are confusing  method with skip.Hope it helps.//Ali
      

  2.   

    翻译一下 javadocs 里面关于 InputStream# 方法的注释,不够了准确,但大概意思是说,如果 InputStream.Supprted() 返回 true 表示能够标记流的当前位置,参数是要求缓冲的最多字节数,比如,在读取了第5个字节之后,(10) 的话,我之后 reset 再来读取的话,这次读取到的前10个字节就是之前从第5个字节开始的10个字节。它能让我们反复地读取同一段内容。
      

  3.   


    非常感谢你的回答 ,()方法里的参数是缓冲的最多字节数,但我发现不管参数是几效果都一样:import java.io.BufferedInputStream;
    import java.io.FileInputStream;public class chinese_english_inputstream {
    public static void main(String[] args) throws Exception {
    FileInputStream fis = new FileInputStream("e:/io流专用文件/da1.txt");
    BufferedInputStream bis = new BufferedInputStream(fis);
    bis.read();
    bis.read();
    bis.(1);         //我这设置的缓冲区为1个字节
    bis.read();
    bis.read();
    bis.read();
    bis.reset();         //在读到e后进行reset
    System.out.println((char)bis.read()+"-"+(char)bis.read()+"-"+(char)bis.read());
    }
    }
    《da1.txt》:
    abcdefg中国人问题:
    控制台的输出是:c-d-e
    按你说的那该是:c-f-g才对啊?