• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Save File into SD Card using loop

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 954
4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic