0

我正在使用一种用 Java 编写的算法,具有这样的输出功能:

DataOutputStream out = new DataOutputStream(new FileOutputStream("lalala.txt"));

out.writeChars(string_double_copy_B[0] + "/" + string_double_copy_B[1] +  "\t");                                            
out.writeChars(String.valueOf(corrValue));                                      
out.writeChars("\n");

corrValue是双。 string_double_copy_B是一个字符串数组。

之后,我尝试使用 ruby​​ 读取生成的文件。我有以下代码。

input=File.open("lala.txt","r")
genes=[]

input.each_line{|li|

    keys=li.split("\t")
    length=keys.length
    puts(keys[length-1].inspect)

}

我得到这样的输出:

"\u00000\u0000.\u00009\u00000\u00000\u00002\u00003\u00003\u00006\u00006\u00001\u‌00005\u00003\u00006\u00000\u00002\u00001\u00005\u0000" 

当 java 将 double 写入文件时,会发生一些问题。我也尝试过PrintWriter out = new PrintWriter(new FileOutputStream("lala...)) 它向我展示了同样的事情。

我该如何解决?那么,为了获得正常的双精度,用 java 编写的适当方法是什么?

kik@kik-VirtualBox:~/Desktop$ od -t a -t x1 stemcells09_negative_werte.txt 
0000000 nul   1 nul   0 nul   5 nul   3 nul   _ nul   a nul   t nul   /
         00  31  00  30  00  35  00  33  00  5f  00  61  00  74  00  2f
0000020 nul   R nul   F nul   C nul   2 nul  ht nul   2 nul   0 nul   3
         00  52  00  46  00  43  00  32  00  09  00  32  00  30  00  33
0000040 nul   6 nul   9 nul   6 nul   _ nul   s nul   _ nul   a nul   t
         00  36  00  39  00  36  00  5f  00  73  00  5f  00  61  00  74
0000060 nul   / nul   R nul   F nul   C nul   2 nul  ht nul   0 nul   .
         00  2f  00  52  00  46  00  43  00  32  00  09  00  30  00  2e
0000100 nul   9 nul   0 nul   3 nul   1 nul   6 nul   9 nul   9 nul   6
     00  39  00  30  00  33  00  31  00  36  00  39  00  39  00  36
4

1 回答 1

0

您编写 String 的二进制表示而不是 String 本身。改用Writer写字符串:

Writer out = new FileWriter("lalala.txt");

out.write(string_double_copy_B[0] + "/" + string_double_copy_B[1] +  "\t");                                            
out.write(String.valueOf(corrValue));                                      
out.write("\n");
于 2013-05-23T20:15:24.003 回答