Java如何将二进制写入文件? 想用Java实现一个二进制文件,内容为000102030405060708090A0B0C0D0E0F101112……FEFF,也就是由00000000,00000001开始,一直到11111111结束。哪位朋友以前遇到过这个问题,麻烦解答下,万分感谢。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 使用FileOutputStream的write方法写入字节不就好了 使用outputStream子类应该可以实现 public static void main(String[] args) { int start = Integer.parseInt("00000000", 2); int end = Integer.parseInt("11111111", 2); byte[] outputData = new byte[end - start + 1]; for (int i = start; i <= end; i++) { outputData[i] = (byte)i; } FileOutputStream fos = null; try { fos = new FileOutputStream("d:\\binaray.bin"); fos.write(outputData); } catch (IOException e) { e.printStackTrace(); } finally { if (fos != null) { try { fos.close(); } catch (IOException e) { e.printStackTrace(); } } } } 记事本文件菜单中“另存为”这段代码怎么写?求解!!! 弄jni的童鞋注意啦 〓〓大家来算算这道题〓〓 java awt 实现颜色管理 关于字母排序问题 求救各位高手 怎样把软件放在邮箱中. 所有窗体控件都有一个句柄叫Handle,如何获取一个JFrame显示时候的Handle呢? 用java怎么实现文件拷贝? 大家有没有关于jni方面的中文资料,最近要用到。多谢了。 多线程 Thread IO操作的一个问题
public static void main(String[] args) { int start = Integer.parseInt("00000000", 2);
int end = Integer.parseInt("11111111", 2);
byte[] outputData = new byte[end - start + 1];
for (int i = start; i <= end; i++) {
outputData[i] = (byte)i;
}
FileOutputStream fos = null;
try {
fos = new FileOutputStream("d:\\binaray.bin");
fos.write(outputData);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}