展开全部
试试
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class $ {
public static void main(String[] args) throws FileNotFoundException {
String path = "D:/a.txt";
Scanner in = new Scanner(new File(path));
List data = new ArrayList();
while (in.hasNextLine()) {
// 取第一行
String s = in.nextLine();
int idx = s.indexOf(" ");
String s0 = s.substring(0, idx);
String s1 = s.substring(idx + 1, s.length() - 1);
String[] arrs = { s0, s1 };
data.add(arrs);
}
for (int i = 0; i < data.size(); i++) {
String[] arr = (String[]) data.get(i);
System.out.println("第" + (i + 1) + "行是:" + arr[0] + "\t" + arr[1]);
}
}
}
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class $ {
public static void main(String[] args) throws FileNotFoundException {
String path = "D:/a.txt";
Scanner in = new Scanner(new File(path));
List data = new ArrayList();
while (in.hasNextLine()) {
// 取第一行
String s = in.nextLine();
int idx = s.indexOf(" ");
String s0 = s.substring(0, idx);
String s1 = s.substring(idx + 1, s.length() - 1);
String[] arrs = { s0, s1 };
data.add(arrs);
}
for (int i = 0; i < data.size(); i++) {
String[] arr = (String[]) data.get(i);
System.out.println("第" + (i + 1) + "行是:" + arr[0] + "\t" + arr[1]);
}
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询