Kotlin Program to Convert File to byte array and Vice-Versa
import java.io.IOException
import java.nio.file.Files
import java.nio.file.Paths
import java.util.Arrays
fun main(args: Array<String>) {
val path = System.getProperty("user.dir") + "\\src\\test.txt"
try {
val encoded = Files.readAllBytes(Paths.get(path))
println(Arrays.toString(encoded))
} catch (e: IOException) {
}
}
Output:
[84, 104, 105, 115, 32, 105, 115, 32, 97, 13, 10, 84, 101, 115, 116, 32, 102, 105, 108, 101, 46]
