提取数字和排序列

时间:2014-04-09 01:42:48

标签: java

我想创建一个Java程序,其中包含以下文本文件作为输入:

Calculating KNN parameter
Parameter: 1 Positions: 290 Avg. Error: 1.7535227753624112

Parameter: 2 Positions: 290 Avg. Error: 3.7245670622636187

Parameter: 3 Positions: 290 Avg. Error: 3.9362841303832017

Parameter: 4 Positions: 290 Avg. Error: 4.843214570109396

Parameter: 5 Positions: 290 Avg. Error: 5.272961320042017

Parameter: 6 Positions: 290 Avg. Error: 5.470106704332144

Parameter: 7 Positions: 290 Avg. Error: 5.882240503856739

Parameter: 8 Positions: 290 Avg. Error: 6.292034572575386

Parameter: 9 Positions: 290 Avg. Error: 6.768597736578583

Parameter: 10 Positions: 290 Avg. Error: 7.363156542812285

Parameter: 11 Positions: 290 Avg. Error: 7.94830050269379

Parameter: 12 Positions: 290 Avg. Error: 8.66008903038875

Parameter: 13 Positions: 290 Avg. Error: 9.114407610375434

Parameter: 14 Positions: 290 Avg. Error: 9.613416435385924

Parameter: 15 Positions: 290 Avg. Error: 9.996985154183648
Done!
Calculating WKNN parameter
Parameter: 1 Positions: 290 Avg. Error: 1.7535225490195745

Parameter: 2 Positions: 290 Avg. Error: 2.828108501703112

Parameter: 3 Positions: 290 Avg. Error: 3.103403533760642

Parameter: 4 Positions: 290 Avg. Error: 3.6864500170894723

Parameter: 5 Positions: 290 Avg. Error: 4.040592423213244

Parameter: 6 Positions: 290 Avg. Error: 4.184767230931307

Parameter: 7 Positions: 290 Avg. Error: 4.473391782511176

Parameter: 8 Positions: 290 Avg. Error: 4.682784733026703

Parameter: 9 Positions: 290 Avg. Error: 4.959394725752682

Parameter: 10 Positions: 290 Avg. Error: 5.256765042378009

Parameter: 11 Positions: 290 Avg. Error: 5.5007236666369534

Parameter: 12 Positions: 290 Avg. Error: 5.844052147012272

Parameter: 13 Positions: 290 Avg. Error: 6.120608429925178

Parameter: 14 Positions: 290 Avg. Error: 6.385641690580632

Parameter: 15 Positions: 290 Avg. Error: 6.62154087396507
Done!
Calculating MAP parameter
Parameter: 1 Positions: 290 Avg. Error: 2.1619860115120555

Parameter: 2 Positions: 290 Avg. Error: 1.7535225490195743

Parameter: 3 Positions: 290 Avg. Error: 1.7535225490195743

Parameter: 4 Positions: 290 Avg. Error: 1.7535225490195743

Parameter: 5 Positions: 290 Avg. Error: 1.7535225490195743

Parameter: 6 Positions: 290 Avg. Error: 1.7535225490195743

Parameter: 7 Positions: 290 Avg. Error: 1.7535225490195743

Parameter: 8 Positions: 290 Avg. Error: 1.7535225490195743

Parameter: 9 Positions: 290 Avg. Error: 1.7535225490195743

Parameter: 10 Positions: 290 Avg. Error: 1.7535225490195743
Done!
Calculating MMSE parameter
Parameter: 1 Positions: 290 Avg. Error: NaN

Parameter: 2 Positions: 290 Avg. Error: 1.7498889149108856

Parameter: 3 Positions: 290 Avg. Error: 1.7806398141014868

Parameter: 4 Positions: 290 Avg. Error: 1.8209795860443478

Parameter: 5 Positions: 290 Avg. Error: 1.8764885946976129

Parameter: 6 Positions: 290 Avg. Error: 1.9505246960583114

Parameter: 7 Positions: 290 Avg. Error: 2.041719152989117

Parameter: 8 Positions: 290 Avg. Error: 2.1448642832455125

Parameter: 9 Positions: 290 Avg. Error: 2.253804843291688

Parameter: 10 Positions: 290 Avg. Error: 2.365860366623
Done!

我希望在平均后提取数字。错误然后对它们进行排序,最后将它们作为输出写入其他文本文件,例如对于前一个样本,这是所需的输出:

1.749888915
1.753522549
1.753522549
1.753522549
1.753522549
1.753522549
1.753522549
1.753522549
1.753522549
1.753522549
1.753522549
1.753522775
1.780639814
1.820979586
1.876488595
1.950524696
2.041719153
2.144864283
2.161986012
2.253804843
2.365860367
2.828108502
3.103403534
3.686450017
3.724567062
3.93628413
4.040592423
4.184767231
4.473391783
4.682784733
4.84321457
4.959394726
5.256765042
5.27296132
5.470106704
5.500723667
5.844052147
5.882240504
6.12060843
6.292034573
6.385641691
6.621540874
6.768597737
7.363156543
7.948300503
8.66008903
9.11440761
9.613416435
9.996985154

有关如何实现这一目标的任何建议?

这是读取文件的代码:

public class extract2 {
    public static void main (String[] args) throws java.lang.Exception
    {
    File inputFile = new File("offline1.txt");
    File tempFile = new File("offline_out.txt");
    File inputFile1 = new File("testing.txt");
    File tempFile1 = new File("testing_out.txt");
}

我想怎么做:  逐行读取文件并在"之后提取数字:"并将它sabe成一个arraylist,然后对数组列表中的元素进行排序,最后写出数组列表的结果

1 个答案:

答案 0 :(得分:0)

Set<Double> set = new TreeSet();
br = new BufferedReader(new InputStreamReader(file, Charset.forName("UTF-8")));
while ((line = br.readLine()) != null) {
     if(line.contains("Error) {
      set.add(Double.valueOf(line.split("Error: ")[1]));
     }
}

在集合中,您已经订购了错误值,只需将它们打印出来。