DataInputStream/DataOutputStream are used for binary stream, not ascii stream.
a simple sample how to use them:
try{
DataOutputStream out=
new DataOutputStream(new FileOutputStream("data.txt"));
out.writeByte(1);
out.writeInt(2);
out.flush();
out.close();
}catch(IOException e){
e.printStackTrace();
}try{
DataInputStream dis = new DataInputStream(
new FileInputStream("data.txt"));
int a=dis.readByte();
System.out.println(a);
a=dis.readInt();
System.out.println(a);
dis.close();
}catch(IOException e){
e.printStackTrace();
}
a simple sample how to use them:
try{
DataOutputStream out=
new DataOutputStream(new FileOutputStream("data.txt"));
out.writeByte(1);
out.writeInt(2);
out.flush();
out.close();
}catch(IOException e){
e.printStackTrace();
}try{
DataInputStream dis = new DataInputStream(
new FileInputStream("data.txt"));
int a=dis.readByte();
System.out.println(a);
a=dis.readInt();
System.out.println(a);
dis.close();
}catch(IOException e){
e.printStackTrace();
}
解决方案 »
- 重写toString()想要通过 return 打印出数组???
- 一段小代码运行出错?跪求解决~~~~估计是API的加载[我是菜鸟]
- 关于Ant的命令
- 求 JAVA画线解决方案!
- 推荐下书网址.
- jdk1.5.0装好了,可是还是运行1.4.2。怎么办:-(高手指教
- 怎样将.class生成.exe文件哪?
- ------------关于TCP滑动窗口的演示 急!!!-------
- 请问:哪里有支持断点续传的JBuilder 5 正式版下载?
- JBuilder中没有JDataStore吗?如果有那JDataStore的序列号和KEY是什么?
- 散分了
- 怎么在一个自运行系统创建一个mysql数据库以及里面的表?
Reads four input bytes and returns an int value. Let a be the first byte read, b be the second byte, c be the third byte, and d be the fourth byte. The value returned is:
(((a & 0xff) << 24) | ((b & 0xff) << 16) |
((c & 0xff) << 8) | (d & 0xff))
For your example:Input 1:
You will get ch1 =49,ch2 =13,ch3=10
after you Input 2:
you get ch4 =50
then:
((ch1 << 24) + (ch2 << 16) + (ch3 << 8) + (ch4 << 0)) = 822938162
Thanks for your advice.