so that later i can parse the array and if the line contains 3 doubles store it into an array of object type? ill later have to store the lines with 3 doubles into another array.
这样以后我就可以解析这个数组如果这个行包含3个双打将它存储到一个对象类型数组中?稍后,我必须将3倍的行存储到另一个数组中。
here's an example of my code so far
下面是我的代码示例。
public static void readFile(){
Scanner scnr = null;
File info = new File("info.txt");
try {
scnr = new Scanner(info);
} catch (FileNotFoundException e) {
System.out.println("file not found");
e.printStackTrace();
}
int counterLines = 0;
String nextLine = "";
while(scnr.hasNextLine()){
nextLine = scnr.nextLine();
counterLines ++;
}
System.out.println(counterLines);
String[] infoArray = new String[counterLines];
for(int i = 0; i < counterLines; i++){
infoArray[i] = scnr.nextLine();
System.out.println(infoArray[i]);
1 个解决方案
#1
0
You can probably spilt the text of the file into individual words using String.split() which gives you a String array.
您可以使用String.split()将文件的文本溢出到单个单词中。
#1
0
You can probably spilt the text of the file into individual words using String.split() which gives you a String array.
您可以使用String.split()将文件的文本溢出到单个单词中。