Converts the double argument to a long using the doubleToLongBits method in class Double, and then writes that long value to the underlying output stream as an 8-byte quantity, high byte first. If no exception is thrown, the counter written is incremented by 8.如上所述,DataOut和DataInput都是在存储时对数据进行一次转换
直接从txt文件里是读不到正确的数据的,
必须用DataInputStream来完成读取(个人意见,不足为信,俺也是初学者)
使者用以下程序读读试吧(我没有运行过阿)
class Read{
public void Read() throws IOException {
DataInputStream in = new
DataInputStream(new FileInputStream("c:\\acc.txt"));
for(int i =0 ;i<2;i++)
{
System.out.println(in.readDouble());
System.out.println(in.readInt());
System.out.println(in.readChar());
}
in.close();
}
}
直接从txt文件里是读不到正确的数据的,
必须用DataInputStream来完成读取(个人意见,不足为信,俺也是初学者)
使者用以下程序读读试吧(我没有运行过阿)
class Read{
public void Read() throws IOException {
DataInputStream in = new
DataInputStream(new FileInputStream("c:\\acc.txt"));
for(int i =0 ;i<2;i++)
{
System.out.println(in.readDouble());
System.out.println(in.readInt());
System.out.println(in.readChar());
}
in.close();
}
}
解决方案 »
- 问一个批量更新数据的sql
- 关于生成对象出错?
- 请叫高手关于有关联的显示的问题,小弟是初学者
- 有没有比JUnit更好的单元测试工具啊?
- 如何用RunTime.getRunTime.exec()来打开一个excel文件(c:\\demo.xls)
- Java中ToolBar的使用方法?
- 一个关于对象访问类成员变量的问题
- [初学者问题]我现在配置好了Tomcat,想连接SQLserver,需要下载什么文件吗?
- 小问题,却烦到小第几天,请教手工建立form的各种方法,建议。
- java程序调试实用手册 哪里有电子版下载?!!!!!!!!!!!!!!!!
- 初学者问题,有三个错误
- 对两个XML文件内容进行比较,如何得到不同的地方?或者给点思路!
<<
40 29 FA E1 47 AE 14 7B 00 09 00 00 00 0C 00 09
00 54 00 2D 00 73 00 68 00 6F 00 75 00 74 40 21
CC CC CC CC CC CD 00 09 00 00 00 09 00 09 00 58
00 4D 00 4C 00 2D 00 42 00 6F 00 62 00 6C 00 65
>>
先看你写的第一个是double 12.99
你试试这样输出什么?<<Long.toHexString(Double.doubleToLongBits(12.99))>>
输出结果是<<4029fae147ae147b>>,正是你的数据文件中的第一个数:
40 29 FA E1 47 AE 14 7B (64 bit)
而后是一个char '\t': 00 09 (16bits)
然后输出一个int 12: 00 00 0C 00 (32bits)
又是一个char '\t':00 09 (16 bits)
然后是字符串:"T-shout":00 54 00 2D 00 73 00 68 00 6F 00 75 00 74
看。一个也没有错。
<<
public class TestData {
public static void main(String[] args) throws IOException {
double[] priees = {12.99, 8.9};
String[] name = {"T-shout", "XML-Boble"};
int[] units = {12, 9};
BufferedWriter out = new BufferedWriter(new FileWriter("H:\\acc.txt"));
for (int i = 0; i < priees.length; i++) {
StringBuffer sbuf = new StringBuffer();
sbuf.append(priees[i]).append("\t").append(units[i]).append("\t");
sbuf.append(name[i]).append("\n"); out.write(sbuf.toString());
}
out.close();
}
}>>
我刚才试了一下你的程序,好象还是不行,文本文件内容是空的。为什么用out.writeDouble(priees[i]);输出不行呢?
把out.write(sbuf.toString())改成out.writeChars(sbuf.toString())就可以了.