1. 程式人生 > >DICOM檔案轉16進位制

DICOM檔案轉16進位制

話不多說直接上程式碼
package com.cn;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;


public class text {
	   static FileInputStream input;
	    static byte[] b;
	public static void main(String[] args) {
		 try {
	            File file = new File("C:/Users/software/Desktop/DCM (1)/011958333339.dcm");
	            input = new FileInputStream(file);
	            b = new byte[(int) file.length()];
	            input.read(b);
	        } catch (FileNotFoundException e) {
	            e.printStackTrace();
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
	        init();
	}
	public static void init(){
		System.out.println("b.length="+b.length);
        for (int i =0;i<10000;i++) {
        if (b[i]<0) {
                int temp=b[i]+256;
                System.out.print(Integer.toHexString(temp));
            }else{
                System.out.print(Integer.toHexString(b[i]));
            }

            if (i%16==15) {
                System.out.println();
            }else{
                System.out.print(", ");
            }
        }
    }
}