Cannot Write file into SDCard

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

Cannot Write file into SDCard

Postby xiaodar » Thu May 27, 2010 8:35 am

Hi fellow developers, i'm having this issue of not being able write text file into the SDCard.
I'm running the program through eclipse on a HTC magic version 2.1.
i had the USB cable unplugged before i run the program.
It says that the parent directory of file does not exist: data2/abc.text

Can any1 help me on this, thanks in advance

The button that trigger the saving
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.     btnSave.setOnClickListener(new View.OnClickListener() {
  2.  
  3.                 public void onClick(View v) {
  4.                         try {  
  5.                                
  6.                                    
  7.                                    boolean success = (new File("data2")).mkdir();
  8.                                     if (success) {
  9.                                        
  10.                                         Toast.makeText(Test.this, "Success", Toast.LENGTH_SHORT).show();
  11.                                    
  12.                                     }  
  13.                        
  14.                        
  15.  
  16.                                
  17.                                  
  18.                                 File gpxfile = new File("data2/abc.txt");  
  19.                                
  20.                                 if(!gpxfile.exists()){
  21.                                         gpxfile.createNewFile();
  22.                                
  23.                                
  24.                                
  25.                                 FileWriter gpxwriter = new FileWriter(gpxfile);        
  26.                                 BufferedWriter out = new BufferedWriter(gpxwriter);        
  27.                                 out.write("b");      
  28.                                 out.close();
  29.                                 Toast.makeText(Test.this, "Success2", Toast.LENGTH_SHORT).show();
  30.                                 }
  31.                         }
  32.                         catch (IOException e) {  
  33.                                 Toast.makeText(Test.this, e+"", Toast.LENGTH_SHORT).show();                            
  34.                                 }
  35.                 }
  36.                
  37.  
  38.         });    
  39.         }
  40.        
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


i did add this permission in the manifest file
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.   <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Parsed in 0.000 seconds, using GeSHi 1.0.8.4
xiaodar
Junior Developer
Junior Developer
 
Posts: 16
Joined: Wed Mar 24, 2010 9:51 am

Top

Re: Cannot Write file into SDCard

Postby asolanki » Fri May 28, 2010 7:37 am

Hi!!

if you want to create file on SDCard then you should write path like /sdcard/data2/abc.txt
asolanki
Senior Developer
Senior Developer
 
Posts: 151
Joined: Thu Jan 08, 2009 7:32 am

Re: Cannot Write file into SDCard

Postby JKumar » Wed Jun 02, 2010 8:09 am

Hi,

Can you post the file writing code to understand the problem better.?
Hope the suggestion helps you
Keep posting .It makes us better to understand Android
User avatar
JKumar
Experienced Developer
Experienced Developer
 
Posts: 52
Joined: Thu May 13, 2010 8:17 am
Location: INDIA

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 29 guests