Android File Utils
Android 10 (API Level 29) introduces a new utility class related to file operations named FileUtils
.
Copying File​
FileUtils
class contains several methods for performing copy operations.
Copying File with InputStream/OutputStream​
If you're using stream, you can use this copy()
method:
import android.os.Build
import android.os.FileUtils
import java.io.File
val inputStream = "Hello Android Notebook".byteInputStream()
val file = File.createTempFile("copied_file", ".txt")
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
FileUtils.copy(
inputStream,
file.outputStream(),
)
}