从字符串行格式txt文件中过滤出双精度值

时间:2018-07-19 12:26:01

标签: java eclipse

我得到了以下代码:

static String[] stringArray = new String[] { "pe", "holz", "Analyser_Feuchtigkeit_MED", "ppk", "ps" };

public static void main(String[] args) throws IOException {

    final String filename = "C:...";
    BufferedReader br = null;

    try {
        br = new BufferedReader(new FileReader(filename));
        String line = br.readLine();
        while (line != null) {// file lesen
            if (line.contains("InputParameters (")) {// InputParam

                System.out.println(line.substring(line.indexOf("(") + 1, line.indexOf(")")));

                for (int i = 0; i < stringArray.length; i++) {
                    if (stringArray[i].equals(stringArray[i] + 1)) {
                        String tmp = stringArray[i] + 1;
                        Double x = Double.valueOf(stringArray[i]);
                        Double y = Double.valueOf(tmp);

                        if (x < 0.5 && x < y) {//filter

                            System.out.println(x);
                        } else if (y < 0.5 && y < x) {

                            System.out.println(y);
                        }

                        if (y > 1 && y > x) {
                            System.out.println(y);
                        } else if (x > 1 && x > y) {
                            System.out.println(x);
                        }

                    }

                } // end for
            }
            line = br.readLine();

        } // end while

    } catch (Exception e) {

    } finally {
        try {
            br.close();
        } catch (IOException e) {
        }
    }
}}

现在我得到一些打印输出,例如:p> 0.5,x <= 1.5,p <= 0.9,p <= 0.2,x> = 3
                                p> = 1,x <2,x <0.5,p <0.2

我需要删除不必要的值。因此,在每一行中,我只需要一个p值和一个x值。如何检查每行是否多于1 p,然后检查哪一条最接近0,以保持最小值,如果该值大于1,则保持最大值?

我已经在循环中尝试过

0 个答案:

没有答案