关于IO流,想问下java中怎么将50个整数以二进制形式写入到文件中,然后再将这50个...
关于IO流,想问下java中怎么将50个整数以二进制形式写入到文件中,然后再将这50个数从文件中读取出来。 fos.write(bytes)方法知道,但是整数转二进制后,再将四个字节的二进制转化为一个字节会损失字节 谢谢鱼币 鱼币! 领!String inputFileText="D:\\test\\a.txt";
File file = new File(inputFileText);
FileWriter fileWriter = new FileWriter(file);
BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
for (int i = 0; i < 50; i++) {
bufferedWriter.write(i+"");
}
bufferedWriter.close();
BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
String s = bufferedReader.readLine();
System.out.println(s);
bufferedReader.close();
效果:
012345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
页:
[1]