简体   繁体   中英

(Kotlin) How to save hashmap output to file

I am having trouble writing the contents of my hashmap to a file when I select the option. I have successfully read from a file, and utilized various functions to adjust my catalog of products. However, every time I choose my save option. The file clear minus 1 of the products.

Thank you. I appreciate any help in regards to solving this issue.

You should close the file printer after writing all the records to the file.

Move fd.close() out of the for-loop.

for (record in products) {
    fd.println("${record.key},${record.value.first},${record.value.second}")
    // fd.close() << from here
}
fd.close() // to here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM