title: Reading files from a dir on the sdcard
body: <p>I'm trying to read a dir and within this dir I have files for each contact. I want to to be able to read those contacts and then put them into the listview. I have tried but, I get a Java error and tried to research it more and found out when I try to do:</p>
  
  <pre><code>fileInputStream fi = fileInput(sdcard/contacts, 0);
  fi.read();
  //then the parse.
  </code></pre>
  
  <p>As I said I tried this and get an error which means I can't access a dir with the method above as that method is looking for app specific data.</p>
  
  <p>My Code so far:</p>
  
  <pre><code>private void checkFosImprtCtacs() {
          String FILENAME = "check";
          String RND = "LewisR";
          OutputStream out = null;
          // TODO Auto-generated method stub
          /*
           * Check if the dir exists, if it does we'll load the contacts, if it
           * doesn't the user will be presented with a dialog box and if they hit
           * yes the contacts will be written to the SD card see the
           * importcontacts theory file.
           */
          File dir = new File(Environment.getExternalStorageDirectory()
                  + "/chckcontacts");
          if (dir.exists() &amp;&amp; dir.isDirectory()) {
              dir.exists();
              dir.getPath().getBytes().toString(
                      //yes I KNOW THIS CODE IS WRONG, I JUST WANTED TO SHOW SOMETHING.
              BufferedReader inputReader = null;
              while (dir.getPath().getBytes() != null) {
  
              }
  
  
  
  
          } else {
              if (dir.exists())
                  ;
              {
                  dir.mkdir();
                  // import contacts via dialog box.
                  new AlertDialog.Builder(this)
                          .setTitle("Import Contacts")
                          .setMessage("Do you want to import your contacts?")
                          .setPositiveButton("Yes",
                                  new DialogInterface.OnClickListener() {
                                      public void onClick(DialogInterface dialog,
                                              int which) {
                                          Cursor cursor = getContacts();
                                          while (cursor.moveToNext()) {
                                              String displayName = cursor.getString(cursor
                                                      .getColumnIndex(ContactsContract.Data.DISPLAY_NAME));
                                              Log.e(displayName, displayName);
                                              // create a File object for the
                                              // parent directory
                                              File Contacts = new File(
                                                      Environment
                                                              .getExternalStorageDirectory()
                                                              + "/contacts");
                                              // have the object build the
                                              // directory structure, if needed.
                                              Contacts.mkdirs();
                                              // create a File object for the
                                              // output file
                                              File outputFile = new File(
                                                      Contacts,
                                                      displayName);
                                              // now attach the OutputStream to
                                              // the file object, instead of a
                                              // String representation
                                              try {
                                                  FileOutputStream fos = new FileOutputStream(
                                                          outputFile);
                                              } catch (FileNotFoundException e) {
                                                  // TODO Auto-generated catch
                                                  // block
                                                  e.printStackTrace();
                                              }
                                          }
                                      }
                                  })
                          .setNegativeButton("No",
                                  new DialogInterface.OnClickListener() {
                                      public void onClick(DialogInterface dialog,
                                              int which) {
                                          // do nothing
                                      }
                                  }).show();
  
              }
          }
      }
  
      private Cursor getContacts() {
          // TODO Auto-generated method stub
          Uri uri = ContactsContract.Contacts.CONTENT_URI;
          String[] projection = new String[] { ContactsContract.Contacts._ID,
                  ContactsContract.Contacts.DISPLAY_NAME };
          String selection = ContactsContract.Contacts.IN_VISIBLE_GROUP + " = 1";
          String[] selectionArgs = null;
          String sortOrder = ContactsContract.Contacts.DISPLAY_NAME
                  + " COLLATE LOCALIZED ASC";
          return managedQuery(uri, projection, selection, selectionArgs,
                  sortOrder);
  
      }
  </code></pre>