/
pav_nk
/
kotlin-object-oriented-programming
Обзор
Документация
Войти
/
pav_nk
/
kotlin-object-oriented-programming
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/files/WorkingWithFiles.kt
41 строка
1 KB
pavel
3.15 lesson completed
29 июл 2026, 16:03
29 июл 2026, 16:03
9971b13
Код
Авторство
О чём код?
package files import java.io.File fun main() { val file = File("test.txt") val operationCodes = OperationCode.entries while(true) { print("Enter the operation code. ") for ((index, code) in operationCodes.withIndex()) { print("$index: ${code.title}") if (index < operationCodes.size - 1) { print(", ") } else { print(": ") } } val operationIndex = readln().toInt() val operationCode = operationCodes[operationIndex] when (operationCode) { OperationCode.EXIT -> break OperationCode.ADD_NEW_ITEM -> { print("Enter todo text: ") val todo = readln() file.appendText("$todo\n") } OperationCode.SHOW_ALL_ITEMS -> { val content = file.readText().trim() if (content.isEmpty()) { println("No items") break } val items = content.split("\n") for ((index, item) in items.withIndex()) { println("$index: $item") } } } } }