Is there a way how to read multiple vcards from only one file using cardme? According to examples show here it seems that it's not possible.
Asked
Active
Viewed 1,313 times
3 Answers
2
There is no build in method to do this. You can iterate the file line by line until END:VCARD
and then use the method VCardEngine.parse(String)
to read each VCard one by one.
Something like this may work:
BufferedReader buffer = new BufferedReader(new FileReader("allcards.txt"));
VCardEngine engine = new VCardEngine();
StringBuilder builder = new StringBuilder();
List<VCard> vcards = new ArrayList<VCard>();
String line;
while ((line = buffer.readLine()) != null) {
builder.append(line);
if (line.contains("END:VCARD")) {
VCard vcard = engine.parse(builder.toString());
vcards.add(vcard);
builder = new StringBuilder();
}
}

jordeu
- 6,711
- 1
- 19
- 19
2
I don't know if the method parseMultiple() is newer than this post, but this is actually possible with the versión I'm using (v0.3.3).
Here's a method that iterates over a Files array, in which each file may have multiple vcards, and adds all the read VCards to a List.
public List<VCard> importVCards() {
List<VCard> vcards = new ArrayList<VCard>();
vcardFiles = getFiles();
for(int i = 0; i < vcardFiles.length; i++){
try {
vcards.addAll(vcardEngine.parseMultiple(vcardFiles[i]));
}
catch(IOException ioe) {
System.err.println("Could not read vcard file:
"+vcardFiles[i].getAbsolutePath());
ioe.printStackTrace();
}
}
return vcards;
}
cardme can be found here:https://github.com/george-haddad/cardme
0
Cardme version 0.3.3 has been released which supports parsing multiple vcards from 1 file. You can download it here http://sourceforge.net/projects/cardme/files/Cardme/Card%20Me%20Version%200.3.3/

george_h
- 1,562
- 2
- 19
- 37