'I tried to save file in cache dir but it display 0 bytes in android

I am trying to save image / video / file into cache folder but it's generate 0 bytes file into my app's cache dir. here is code

try {
                val dir = File(cacheDir.toString(), mURI.lastPathSegment.toString())
                val fOut = FileOutputStream(dir)
                fOut.flush()
                fOut.close()
            } catch (e: java.lang.Exception) {
                e.printStackTrace()
            }

I tried with contentResolver and FileProvider



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source