用 Json 试试。
检查此链接,您将看到从 json 文件中读取是多么简单:
http://answers.oreilly.com/topic/257-how-to-parse-json-in-java/
如果您选中此项,则必须为您的朋友创建一个类:
public class Friend {
String name;
String surname;
String phone;
public Friend(String name, String surname, String phone){
this.name = name;
this.surname = surname;
this.phone = phone;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSurname() {
return surname;
}
public void setSurname(String surname) {
this.surname = surname;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
}
In the class where you parsing the file you can do it like this:
ArrayList<Fried> friends = new ArrayList<Friends>();
// her json parsing
Friend fr = new Friend("Name you parst from Json", .... , ....);
friends.add(fr);
循环执行此操作,您将获得包含 json-file 内容的 ArrayList