In my Kotlin project in folder src/resources/ I has file pairs_ids.txt.
Here code:
This is a property file:
key=value
The count of all lines are 1389.
Here code that read content of this file line by line.
import org.slf4j.LoggerFactory
private val logger = LoggerFactory.getLogger("Exchange")
private var allSymbolsIDsMap: Map<String, String> = mapOf()
val pairsIDs = getResourceAsText("/pairs_ids.txt")
allSymbolsIDsMap = pairsIDs.split(",").associate {
val (left, right) = it.split("=")
left to right.toString()
}
logger.info("allSymbolsIDsMap_size = " + allSymbolsIDsMap.size)
var countAllSymbolHandler = 0
for ((key, value) in allSymbolsIDsMap) {
countAllSymbolHandler++
logger.info("countAllSymbolHandler = $countAllSymbolHandler")
}
private fun getResourceAsText(path: String): String {
return object {}.javaClass.getResourceAsStream(path).bufferedReader().use { it.readText() }
}
Result:
Start project:
allSymbolsIDsMap_size = 1389
Start project - "countAllSymbolHandler =" print 1113 times
Again start project:
allSymbolsIDsMap_size = 1389
"countAllSymbolHandler =" print 242 times
If replace logger.info
by simple println
then success work. The count is always 1389.
Why loop (for) not work correct with logger?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…