yes, it's just as easy to read from an SD card. Here's an example to list the files on an SD card:

        File sdRoot = new File( "/sdcard/" );
        String [] sdRootFiles = sdRoot.list();
        if ( sdRootFiles != null ) {
            int noFiles = sdRootFiles.length;
            Log.v( tag, "number of file found on sd = " + noFiles );
            for ( int i = 0; i < noFiles; i++ ) {
                Log.v( tag, "\t" + sdRootFiles[ i ] );   
            }
        }
        else Log.v( tag, "no sd found" );   

But, before the above works, here's some steps to take to "make an SD card". On the Android tools directory,

1) have a look at 'mksdcard --help'. eg. to create an 8 MB FAT32 file system image named sdcard:
   
   
mksdcard 8M sdcard

2) start the android emulator with the file system you've created:

    emulator -sdcard sdcard &

3) copy a couple of your files into the emulator:

    adb push YOUR_FILE_A /sdcard
    adb push YOUR_FILE_B /sdcard

4) have fun!


Naveen Garg wrote:
Thanks Bruno!! It was really helpful. I would appreciate if you could
tell me how to do this using SD Card.

On May 5, 10:46 am, Bruno Sauer <[EMAIL PROTECTED]> wrote:
  
here's a start: put a "Hello World" message in a file named 'res/raw/helloworld' then try this:        Stringmessage= ""; // get message from file
        Resources resources = getResources();        InputStream xmlStream = resources.openRawResource( R.raw.helloworld );
        try {
            while ( true ) {
                 int b = xmlStream.read();
                 if ( b < 1 ) break; // EOF
                message+= String.valueOf( ( char )b );
            }
            xmlStream.close();
        }
        catch ( IOException e ) {
            Log.e( tag, "IOException'" + e.toString() );
        }
        Log.i( tag, "file message = " +message);
Naveen Garg wrote:Please let me know how to do file handling in Android. Some sample code will be of great use to me. Thanking in advance, Naveen
    


  

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-no...
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to