Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm trying to parse the a datafile.

(我正在尝试解析数据文件。)

This code has worked successfully for my other datfiles;

(该代码已成功地用于我的其他datfiles。)

however, I'm now getting an error.

(但是,我现在遇到一个错误。)

These datafiles are intended therefore the computer is trying to read the first space.

(这些数据文件旨在使计算机尝试读取第一个空格。)

How would I skip over this space?

(我将如何跳过这个空间?)

        String line = br.readLine();
            while (line != null) {

                String[] parts = line.split(" ");

                if (linecounter != 0)
                {
                    for (int j=0; j<parts.length; j++)
                    {

                        if (j==parts.length-1)
                            truepartition.add(Integer.parseInt(parts[j]));
                        else
                        {
                            tempvals.add(Double.parseDouble(parts[j]));
                            numbers.add(Double.parseDouble(parts[j]));
                        }

                    }

                    Points.add(tempvals);
                    tempvals = new ArrayList<Double>();
                }
                else
                {
                    //Initialize variables with values in the first line
                    // Reads each elements in the text file into the program 1 by 1
                    for (int i=0; i<parts.length; i++) {
                        if (i==0)
                            numofpoints = Integer.parseInt(parts[i]);
                        else if (i==1)
                            dim = Integer.parseInt(parts[i]) - 1;
                        else if (i==2)
                            numofclus = Integer.parseInt(parts[i]);
                    }
                }

                linecounter++;
                line = br.readLine();
            }
Data File
     75 3 4
     4    53 0
     5    63 0
    10    59 0

  ask by Anta translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
563 views
Welcome To Ask or Share your Answers For Others

Please log in or register to answer this question.

Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...