SD Card File reading

Put your problem here if it does not fit any of the other categories.

SD Card File reading

Postby Rizwan » Fri Dec 28, 2007 3:59 pm

Hi!
I have mounted SD Card to emulator like this

Code: Select all
mksdcard 2048M mysdcard
emulator -sdcard mysdcard
adb push Hello.txt sdcard/Hello.txt


Then
I executed the simple file reading program

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.                 StringBuffer buffer = new StringBuffer() ;
  2.  
  3.                 File file = null;
  4.  
  5.                 double d_data = 0.0;
  6.  
  7.  
  8.  
  9.                 file = new File("Hello.txt") ;
  10.  
  11.                 try {
  12.  
  13.  
  14.  
  15.                         InputStream file_input = new FileInputStream (file);
  16.  
  17.                         while ((d_data = file_input.read())  != -1) {
  18.  
  19.                                 buffer.append((char)d_data );
  20.  
  21.                         }
  22.  
  23.                         file_input.close ();
  24.  
  25.  
  26.  
  27.                 } catch  (IOException e) {
  28.  
  29.                         buffer.append(e.toString()) ;
  30.  
  31.                 }
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


but I m getting FileNotFoundException . please help me. let me know what I m missing ?

Thanks
Rizwan
Junior Developer
Junior Developer
 
Posts: 18
Joined: Sun Dec 16, 2007 6:35 pm

Top

Postby plusminus » Fri Dec 28, 2007 5:26 pm

Hello ryzwan,

the fault probably is a wrong path. Try:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. file = new File("/sdcard/Hello.txt");
  2.  
  3. // instead of
  4.  
  5. file = new File("Hello.txt");
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


Let us know if it worked :)

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby Rizwan » Fri Dec 28, 2007 5:49 pm

Hi There!

No it did not work , did i need to run the commands every time I start the emulator Am I m mounting SDcard successfully . I did push the file ? still not able to read it please let me know wht i m missing ?

Regards
Rizwan
Junior Developer
Junior Developer
 
Posts: 18
Joined: Sun Dec 16, 2007 6:35 pm

Postby plusminus » Fri Dec 28, 2007 6:06 pm

Hello Rizwan,

no you just have to execute the "mksdcard"-command once
can you see the SDCard and the File in the Eclipse DDMS-View :?:

Did you add the following StartUp-Parameter :?:
[align=center]Image[/align]

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby Rizwan » Fri Dec 28, 2007 6:17 pm

No it's empty what should i put there

-sdcard mysdcard
or
-sdcard C:\Documents and Settings\Neo\Local Settings\Application Data\Android\userdata.img

Thanks for your replies
Rizwan
Junior Developer
Junior Developer
 
Posts: 18
Joined: Sun Dec 16, 2007 6:35 pm

Postby plusminus » Fri Dec 28, 2007 6:24 pm

Hello Rizwan,

just the full path to the sdcard-file you created with the commands in your first post.
If you do not know where it is, just search for files with approximately 2 GigaBytes in size ;).

Did you have a look at the :src: SD-Card Tutorial here on anddev.org :?:
I hope it is easy to understand :)

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Top

Postby Rizwan » Fri Dec 28, 2007 7:19 pm

Thanks !
it is working now :D .
A little problem I m facing is regarding eclipse I have specify the command line argument as
-sdcard mysdcard as mysdscard is in same directory (emulator directory) . it is not working

from console when i run emulator -sdcard mysdcard . it work fine :)
Rizwan
Junior Developer
Junior Developer
 
Posts: 18
Joined: Sun Dec 16, 2007 6:35 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 18 guests