我被要求制作一个字节文件。我得到了数组字节 a[] = {97, 98, 99, 100, 101, 102} ,现在我必须从 a[] 数组中创建字节文件。但我有限制:
- 文件的数据必须是随机的(来自 a[])
必须几乎同时在文件中检测到所有字节。
公共类 WriteByteFile { byte[] a = {97, 98, 99, 100, 101, 102};
最终字符串文件=“文件”;
/* 打开文件 */ BufferedOutputStream out = null; 尝试 { out = new BufferedOutputStream (new BufferedOutputStream(file)); } catch (FileNotFoundException e1) { System.err.println("无法打开文件:" + file1 + ":" + e1.getMessage()); System.exit(1); }
/* 写入文件 */ try { for (int b = 0; b < 1650; b++) { out.write(//这里我必须从 a[] 中获取随机元素,但在接下来的 5 次中不能再获得它) ; }