北极熊77 2010-01-03 14:14
浏览 234
已采纳

如何用fileInputStream读取第十个byte

急用,谢谢请帮忙!

  • 写回答

3条回答 默认 最新

  • chengming5460 2010-01-03 15:32
    关注

    [code="java"]public class test {
    public static void main(String[] args) {
    byte[] tempchars = new byte[1];
    File file = new File("d:/log.txt");
    InputStream str = null;
    try {
    str = new FileInputStream(file);
    try {
    str.skip(9);//跳过前9个字节
    int read = str.read(tempchars, 0, 1);//读取一个字节赋值给tempchars
    str.close();
    System.out.println("read="+read);
    System.out.println("tempchars="+tempchars[0]);
    } catch (IOException e) {
    e.printStackTrace();
    }
    } catch (FileNotFoundException e) {
    e.printStackTrace();
    }
    }
    }[/code]

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?