• Post Reply Bookmark Topic Watch Topic
  • New Topic

Save File into SD Card using loop  RSS feed

 
Juuzou Suzuya
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good day! I need help with regards to my code.

I create and save file into an sd card. But the problem I am encountering is that I am trying to save multiple files one by one using for loop, but only one gets saved.

Below are my codes.





My PatientRecord is this class



and lastly the database command from my database class



Any idea with what I am doing wrong?
 
Tushar Goel
Ranch Hand
Posts: 934
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Put some debugger logs in your application for further troubleshooting. Are you sure your do - while loop is working fine? I am thinking may be some problem is with that.
 
Juuzou Suzuya
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The do while loop in the database part is working fine since I am able to retrieve different blob data. I also successfully stored a jpg file on the sdcard, but only one file. I am trying to save all the data one by one using the for loop but only one data is being saved, sometimes two data, but not all the data is getting fired.
 
Juuzou Suzuya
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was able to solve it, thanks for the help. The problem is the naming convention. Since I am using timestamp without any other unique info for the file name, the ArrayList Execution is faster than a second, that's way most of the file being saved gets the same name and is overwriting.
 
Juuzou Suzuya
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was able to find the error. It has something to do with the naming convention, since I've been using the string "IMG" + the Timestamp without any formulation or addition of unique data, and since ArrayList execution is faster than a second, there are times wherein one file gets the same filename, overwriting the existing file.

Thank you for the help!
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't use Date. Look in the Java® Tutorials for what you should use now.
Never write empty catch blocks. You would suffer an Exception and not know anything has gone wrong.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!