D
D
Denis Akhunov2021-03-05 22:20:21
Kotlin
Denis Akhunov, 2021-03-05 22:20:21

How to copy from one file to another?

For example, there is a condition:
Create a file f whose components are integers. Rewrite positive numbers of file f into file g.
How can this be implemented in Kotlin,e?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
foonfyrick, 2021-03-06
@foonfyrick

val fr = FileReader("f.txt")
    val array=fr.readText()
        .substringAfter(':')
        .substringBefore('К')
        .split(' ')
        .toList()
        .filter { !it.contains('0') && !it.contains('-') }
    println(array)
fr.close()

val newFw = FileWriter("g4.txt")
    var numbers = ""
    numbers = array.toString()
        .substringAfter('[')
        .substringBefore("]")
        .filter { !it.isWhitespace() && !it.equals(',') }
    newFw.append(numbers)
    newFw.close()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question