【发布时间】:2013-02-06 11:20:53
【问题描述】:
如何在分隔符 (" ") 后将空格作为字符串,因为只读取他们的名字。
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
输出:
名字是爱丽丝 名字是丽贝卡 名字是约拿 名字叫丹尼尔
【问题讨论】:
-
你想达到什么输出?