Java如何自定义的byte[]数组写入文件

Java如何自定义的byte[]数组写入文件,第1张

/**

 * 字节数据原型的形式写入到文件

 * @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()

        }

    }

}

byte是十进制的数字。。

给你看个例子:

public class Test {

public static void main(String[] args) {

String str = "b"

byte[] bytes = str.getBytes()

for(byte b:bytes){

System.out.println(b)

System.out.println(Integer.toBinaryString(b))

}

}

}


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/tougao/11476421.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-16
下一篇2023-05-16

发表评论

登录后才能评论

评论列表(0条)

    保存