字符串line.contains()找不到特定字符

时间:2018-08-27 17:27:21

标签: java string step

我正在尝试检测步骤文件行中的某些字符。它在步骤文件中找不到#1331。我正在使用line.contains()查找字符。 编程代码如下。

public class test {
    String line;
    BufferedReader buff;
    FileReader file;
    ArrayList<String> face_bound = new ArrayList<>();
    ArrayList<String> edge_curve = new ArrayList<>();
    int counterTest =0;

    public  test(String filename)
    {
        file  = null;
        try 
        {
            file = new FileReader(new File("test/"+filename+".STEP"));

        }

        catch (FileNotFoundException e) 
        {
            System.err.println("Could not read the step file");
            e.printStackTrace();
        }
        detectionTest();
    }

    public void detectionTest()
    {
        face_bound.add("#1427");
        face_bound.add("#1331");
        try 
        {
           buff = new BufferedReader(file);
            while(true)
            {
                line = buff.readLine();
                if(line.contains(face_bound.get(counterTest)) && line.contains("EDGE_LOOP"))
                {
                    System.out.println("TEST: "+line);
                    String[] currentLine = line.split(",");
                    String[] currentLine1 = currentLine[1].split(" ");
                    System.out.println("EDGE LOOP references:"+ currentLine1[2]);
                    edge_curve.add(currentLine1[2]+" ");
                    counterTest++;
                    if(counterTest==face_bound.size())
                    {
                        break;
                    }

                }

                if(line.contains("END-ISO-10303-21;"))
                {
                    break;
                }

            }
        }
        catch (IOException e) 
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

输出: 测试:#1427 = EDGE_LOOP('NONE',(#1853,#18)); EDGE LOOP参考:#1853

但是代码应该检测#1331并打印其EDGE LOOP参考。

0 个答案:

没有答案