Home > Software design >  Move data/data files in Kotlin
Move data/data files in Kotlin

Time:04-05

Im making an app for editing system files (data/data folder). I know that app needs root permission. How can I move files from one data/data folder to other. I thought that it would be easier to make when executing bash command.

Also maybe you have some useful info or documentation for building apps with root

I tried this

    but.setOnClickListener {
        root
        var testName = "bruh.txt"
        var text = "Help me"
        File( filesDir , testName).writeText(text)

        var dstString = "/data/data/com.test.testinproj/code_cache/"
        var srcString = "/data/data/com.test.testinproj/files/bruh.txt"

        Runtime.getRuntime().exec("mv \"$srcString\" \"$dstString\"")

I expected that it will create file called bruh.txt in filesDir, and will move it to directory i need

CodePudding user response:

You can copy files in Kotlin without making an operating system exec call.

File(srcString).copyTo(
    target = File(dstString, "bruh.txt")
)

You can also copy files recursively, which may be easier, if you have multiple files to deal with.

  • Related