2011-10-04 4 views
0
private void readRandomContacts() throws IOException 
{ 

BufferedReader bufRdr; 
contacts = new ArrayList<Contacts>(); 

File randomContactsFile = new File("C:\randomContacts.csv"); 
try { 
    bufRdr = new BufferedReader(new FileReader(randomContactsFile)); 
    String line = null; 
    String[] a = new String[2]; 

     while ((line = bufRdr.readLine()) != null) 
       { 
        a = line.split(","); 
        Contacts c = new Contacts(a[0], a[1], a[1], a[1], a[2]); 
        contacts.add(c); 
       } 

    } catch (FileNotFoundException e) { 
     Log.d("file not found", "check"); 
     e.printStackTrace(); 
    } 

Je ne peux pas sembler lui faire trouver le fichier et randomContacts.csv existe en effet dans le répertoire C. Toute aide s'il vous plaît?ne peut pas trouver le fichier

+0

est-il lancer une exception? – smp7d

+0

oui une exception filenotfound! :/ – michelle

Répondre

3

Essayez avec:

File randomContactsFile = new File("C:\\randomContacts.csv"); 
             ^^ these two are important 

Voir here quelques informations sur les caractères et séquences d'échappement.

1
File randomContactsFile = new File("C:\randomContacts.csv"); 

devrait être

File randomContactsFile = new File("C:\\randomContacts.csv"); 

Vous devez échapper \, sinon, java lirait comme \r retour chariot.

+0

i tried..for rien:/ – michelle

+0

10-04 14: 54: 47,009: WARN/System.err (333): java.io.FileNotFoundException: /C:/test/randomcontacts.txt (Aucun fichier ou annuaire) – michelle

0

vous pouvez aussi le faire (frontslash):

new File("C:/randomContacts.csv") 
Questions connexes