[code=Java]
        byte[] b = {33,44,55,66,77,88,99};
        DataOutputStream d = new DataOutputStream(new FileOutputStream("c:/d.txt"));
        d.write(b);
        d.flush();
/code]怎么才能把这些写入到文件显示为33445566778899而不是显示为对应的ascii值

解决方案 »

  1.   

    byte与char的关系
    byte与int的关系
    int与字符串的关系/**
     * 字节数据原型的形式写入到文件
     * @version 2010-4-25
     */
    public class BitIO {
        /**
         * 测试入口
         * @param args arguments
         */
        public static void main(String[] args) {
            byte[] buffer = {33, 66, 99, 88};
            File fileInst = new File("C:\\BitIO.txt");
            try {
                FileWriter fw = new FileWriter(fileInst);
                for (byte i : buffer) {
                    fw.write(String.valueOf((int) i));
                }
                fw.flush();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException ioe) {
                ioe.printStackTrace();
            }
        }
    }
      

  2.   

    如果有大于127的byte,还需要加上&0xFF,如下
    byte i = (byte) 200;
    System.out.println(Integer.valueOf((int)i));
    System.out.println(Integer.valueOf((int)i&0xFF));
      

  3.   

    完全没有意义的东西
    你不就是要把byte直接以int输出吗!!
      

  4.   


    byte会大于127吗  完全没有意义的东西
      

  5.   

    谢谢2楼就是这样的我忘了前面强制转换成int所以老是出错.