![Java如何自定义的byte[]数组写入文件,第1张 Java如何自定义的byte[]数组写入文件,第1张](/aiimages/Java%E5%A6%82%E4%BD%95%E8%87%AA%E5%AE%9A%E4%B9%89%E7%9A%84byte%5B%5D%E6%95%B0%E7%BB%84%E5%86%99%E5%85%A5%E6%96%87%E4%BB%B6.png)
* 字节数据原型的形式写入到文件
* @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))
}
}
}
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)