Java: File to Hex?

后端 未结 4 1521
别跟我提以往
别跟我提以往 2020-12-16 19:37

I have a file in Java

FileInputStream in = null;
try{    
in = new FileInputStream(\"C:\\\\pic.bmp\");
}catch{}

I want to convert pic.b

4条回答
  •  既然无缘
    2020-12-16 20:24

    Java has an extensive image reading/writing and editing library. Look at the javax.imageio packages (here's the documentation). You would probably want to create a BufferedImage using ImageIO and then access the image data from the BufferedImage object (there are methods for that).

    If you want a generic answer, for any type of binary data (not just images), then I guess you would have to read the contents of the file into a byte array. Something like this:

    byte[] bytes = new byte[in.available()];
    in.read(bytes);
    

提交回复
热议问题