我如何在分隔符(“”)之后将空格作为字符串,因为只有他们的名字被读取。
public class readfile {
public static void main(String[] args) throws IOException {
String readFile = "";
int i;
if (args.length == 1) {
readFile = args[0];
BufferedReader reader = new BufferedReader(new FileReader(readFile));
List<String> read = new ArrayList<String>();
String rLine;
while ((rLine = reader.readLine()) != null) {
String[] items = rLine.split(" ");
if (items[0].equals("Name")) {
for (i = 1; i < items.length; i++) {
String name = items[1];
}
System.out.println("Name is " + items[1]);
}
}
}
}
}
Classlist.txt
Name Alice Mark
Name Rebecca Appel
Name Jonah BullLock Jacob
Name Daniel Ethan Aron
输出:
名字是爱丽丝 名字是丽贝卡 名字是约拿 名字是丹尼尔