首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何从DataInputStream java中只获取文件的前8个字节

如何从DataInputStream java中只获取文件的前8个字节
EN

Stack Overflow用户
提问于 2016-11-21 21:44:18
回答 1查看 571关注 0票数 0

目前正在编写一个java swing程序。它从驱动器中获取所有文件并检查二进制签名。但我只想让文件的前2-8个字节来加速编程。尝试了大多数已经可用的解决方案,但没有一个与我已经编写的代码一起工作。

当前代码:

代码语言:javascript
运行
复制
 public void getBinary() {

    try {


        // get the file as a DataInputStream
        DataInputStream input = new DataInputStream(new FileInputStream(file));

        try {

            // if files are avaliable countinue looping and get bytes / hex 
            while (input.available() > 0) {

                // build  a hex string from the bytes and change to uppercase 
                sb.append(Integer.toHexString(input.readByte()).toUpperCase());


                // need to get the first couple of (8) bytes 
            }



        } catch (IOException e) {
        }

        // print the hex out to command 

        //  System.out.println(sb.toString());

    } catch (FileNotFoundException e2) {
    } 

}
EN

回答 1

Stack Overflow用户

发布于 2016-11-29 21:43:37

对我来说很完美,也可以帮助其他人!

https://i.stack.imgur.com/8SU5A.png

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40721672

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档