0
/* ----------------------------------------------------------------------------
 * Save Deck Configuration
 */
fun exSaveDeck(AppContext: Context,folder : String, newdeckname : String) {

    var i = 0
    val newdeckproperties = Properties()
    val fos: FileOutputStream? = null

    Log.d("exSaveDeck",folder)
    Log.d("exSaveDeck",newdeckname)

    try {
        val file = File(folder,"$newdeckname.pref")
        val fos = FileOutputStream(file)


        // Deck Header
        newdeckproperties.put("deck_name",newdeckname)
        newdeckproperties.put("deck_ncards",mydecklist.size.toString())

        // Cards
        mydecklist.forEach {
            i++
            newdeckproperties.put("card_title."+ i.toString(),it.c_title)
            newdeckproperties.put("card_message."+ i.toString(),it.c_message)
            newdeckproperties.put("card_link."+ i.toString(),it.c_link)
            newdeckproperties.put("card_timer."+ i.toString(),it.c_timer)
            newdeckproperties.put("card_rolldice."+ i.toString(),it.c_rolldice)
            newdeckproperties.put("card_image."+ i.toString(),it.c_image)
            newdeckproperties.put("card_video."+ i.toString(),it.c_video)
            newdeckproperties.put("card_points_math."+ i.toString(),it.c_math)
            Log.d("exSaveDeck",i.toString())
        }

        newdeckproperties.store(fos, "CardGame XXX Deck Save File")

    } catch (e: FileNotFoundException) {
        Toast.makeText(AppContext,"Deck: Saved $newdeckname", Toast.LENGTH_SHORT).show()
    } catch (e: IOException) {
        Toast.makeText(AppContext,"IOEXCeption", Toast.LENGTH_SHORT).show()
    } finally {
        if (null != fos) {
            try {
                fos.close()
            } catch (e: Exception) {
                e.printStackTrace()
            }
        }
    }

} }

You would expect the code flow because it goes from 1...{mydecklist.size} for them to be sequentially out in the file 1,2,3,4.. etc but no! they are randomly scattered about the file in some random fashion, I'm about to re-write the code so that it does properly represent that behavior, but I would like to know why Properties() put just puts it any old place.

Melony Sharon
  • 99
  • 1
  • 8
  • 2
    [`java.util.Properties`](https://docs.oracle.com/javase/8/docs/api/java/util/Properties.html) is a subclass of [`java.util.Hashtable`](https://docs.oracle.com/javase/8/docs/api/java/util/Hashtable.html), which is an **unordered** `Map`. – Andreas Jul 17 '21 at 10:48

0 Answers0