Java 读取每行数据不同的多行文本文件

Java 读取每行数据不同的多行文本文件,java,Java,我试图读取一个文本文件,其中Scanner dataFile=new ScannerFileName.txt;文本文件中的行应该被读取以获取有关它们的信息。我正在使用: while(dataFile.hasNext()){ String line = dataFile.nextLine(); ... } 绕线。我需要在行首提取一个字符串,在字符串后提取一个整数,在整数后提取一个双精度。它们在我需要提取的每个部分之间都有空格,因此我愿意\通过行进行子字符串搜索,以单独搜索

我试图读取一个文本文件,其中Scanner dataFile=new ScannerFileName.txt;文本文件中的行应该被读取以获取有关它们的信息。我正在使用:

while(dataFile.hasNext()){
      String line = dataFile.nextLine();
      ...
}
绕线。我需要在行首提取一个字符串,在字符串后提取一个整数,在整数后提取一个双精度。它们在我需要提取的每个部分之间都有空格,因此我愿意\通过行进行子字符串搜索,以单独搜索行中的部分

我想知道,有没有更简单、更快捷的方法

文本文件的内容示例:

Name 10 39.5
Hello 75 87.3
Coding 23 46.1
World 9 78.3

如果它们都是相同的格式,您可以在空白处拆分

String str = "Name 10 39.5";
String[] arr = str.split(" ");
String s = arr[0];
int i = Integer.valueOf(arr[1]);
double d = Double.valueOf(arr[2]);
你可以用

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

and then str[0] is the string you find
str[1] is the string of Integer ,you cast it
and the str[2] is the string of Double , cast

以空格作为分隔符拆分行:如果可能存在多个空格字符或空格以外的空格,则可能需要在\\s+上拆分。
String[] str=line.split(" ");

and then str[0] is the string you find
str[1] is the string of Integer ,you cast it
and the str[2] is the string of Double , cast