如何从InputStream流中读取制定位置到文件尾的数据流。我的意思是有InputStream我想从流的1024字节开始往后读取到文件尾。

解决方案 »

  1.   

    读取之前先用skip方法跳过1024个字节,再读就ok了,或者用BufferedInputStream的read(byte[] b, int off, int len)可以直接来操作!
      

  2.   

    import java.io.RandomAccessFile;public class RandomReadTest {
    public static void main(String[] args) throws Exception
    {

    RandomAccessFile raf=new RandomAccessFile("randomtest.txt","rw");



    raf.seek(3);
    for(long i=0;i<raf.length();i=raf.getFilePointer())
    {
    System.out.print((char)raf.read());
    }
    raf.close();
    }
    }
    输出结果:456789
    randomtest.txt: 123456789
    RandomAccessFile具有随机读取文件的功能!
    具体用法参考JAVA API!
      

  3.   

    FileInputStream in = new FileInputStream("s.txt");
    byte b[] = new byte[in.available()];//存放字节的数组
    in.read(b,1024,b.length-1024);//从1024开始
      

  4.   

    上面错了:)
    if(in.available()<1024)
     ;//can not
    else {
     in.skip(1024);//跳过1024
     byte b[]  = new byte[in.available() - 1024];//存放字节的数组
     in.read(b);
    }