1

Vcard ファイルを解析しようとしています。これが私のコードです。

public void get_vcf_data(String file) throws VCardException, IOException{
         VCardParser parser = new VCardParser();
            VDataBuilder builder = new VDataBuilder();

            //String file = path;

            //read whole file to string
            BufferedReader reader = new BufferedReader(new InputStreamReader(
                    new FileInputStream(file), "UTF-8"));

            String vcardString = "";
            String line;
            while ((line = reader.readLine()) != null) {
                vcardString += line + "\n";
            }
            reader.close();

            //parse the string
            boolean parsed = parser.parse(vcardString, "UTF-8", builder);
            if (!parsed) {
                throw new VCardException("Could not parse vCard file: " + file);
            }

            //get all parsed contacts
            List<VNode> pimContacts = builder.vNodeList;

            //do something for all the contacts
            for (VNode contact : pimContacts) {
                ArrayList<PropertyNode> props = contact.propList;

                //contact name - FN property
                String name = null;
                String number = null;
                String tel = null;
                for (PropertyNode prop : props) {
                    if ("FN".equals(prop.propName)) {
                        name = prop.propValue;
                        Contact_name.add(name);
                        Log.d("Name", name);
                        //we have the name now
                        break;
                    }
                }
                for (PropertyNode prop : props) {
                    if ("N".equals(prop.propName)) {
                        number = prop.propValue;
                        Contact_number.add(number);
                        Log.d("Name", number);
                        //we have the name now
                        break;
                    }
                }
                for (PropertyNode prop : props) {
                    if(" TEL".equals(prop.propName))
                    {
                        tel = prop.propValue;
                        Contact_tel.add(tel);
                        Log.d("Name", tel);
                    }
                }
                Log.d("Tag", ""+Contact_name.size()+"::"+Contact_number.size()+"::"+Contact_tel.size());

                //similarly for other properties (N, ORG, TEL, etc)
                //...

                System.out.println("Found contact: " + name);
            }
}

しかし、whileループで問題に直面しています

while ((line = reader.readLine()) != null) {
                vcardString += line + "\n";
            }

whileループ内で継続的にループし、ループに入るとループから抜けません

4

0 に答える 0