解决方案 »

  1.   

    我的代码在这里呢
    不好意思阿,我太粗心啦 
    众大神帮忙阿~~
    import java.io.ByteArrayOutputStream;
    import java.io.File;
    import java.io.FileInputStream;
    public class one {
    public static void main(String[]args ) throws Exception{

    outputFileWitHex("/home/wenwen/world.txt");
    } private static void outputFileWitHex(String path) {
    String result;
    int n;
    File file =new File(path);
    try{
     if(!file.exists()){
        System.out.println(file.getName() + "不存在");
     }else{
     System.out.println(file.getName() + "存在");
     }
    FileInputStream in =new FileInputStream(file);
    ByteArrayOutputStream out =new ByteArrayOutputStream();
    byte[] b=new byte[1000];
    while( (n = in.read(b))!= -1){
    out.write(b, 0, n);
    }
    in.close();
    out.close();

    byte [] buffer = out.toByteArray();


    for (int i=0 ;i<buffer.length ;i++){

    String str = Integer.toHexString(buffer[i] & 0xFF);
    result = str.toUpperCase() + "\t";


    if(( i + 1) % 16 == 0)
    result = result + "\n" ;
    System.out.print(result); 
    }
    }catch(Exception e){

    e.printStackTrace();
    }
    }
    }