Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
575 views
in Technique[技术] by (71.8m points)

java - Java试图将意图读取为整数字符串(Java trying to read intention as an Integer string)

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

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

Please log in or register to reply this article.

OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...