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();
}
}

解决方案 »

  1.   

    俺来帮你分析,你生成的文件16进制下是这样的:
    <<
    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
    看。一个也没有错。
      

  2.   

    如果你的原意是要按照文本方式写,俺帮你改了一下程序,你看这样写:
    <<
    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();
        }
    }>>
      

  3.   

    xiaohaiz:
        我刚才试了一下你的程序,好象还是不行,文本文件内容是空的。为什么用out.writeDouble(priees[i]);输出不行呢?
      

  4.   

    现在好了,往往各位的帮忙。我修改了一下xiaohaiz的程序,现在能通过了。
    把out.write(sbuf.toString())改成out.writeChars(sbuf.toString())就可以了.