File is not generated when I write to FileOutputStream on Android

Asked 2 years ago, Updated 2 years ago, 113 views

I am writing the file output on Kotlin.
If you check the operation, there is no error and no file is generated even though it is written.

file.createNewFile()

If you first generate and write the file in , the file is still empty.

Permission is also specified (if there is a problem, it will be an error)

Please let me know if anyone knows how to solve it.

var file=TMP_AUDIO_FILE
    Log.i("TAG", ">>>>" + file.absolutePath)
    valsData=ShortArray(BUFFER_SIZE/2)

    try{
        varos=openFileOutput(file.absolutePath.replace("/", " ""), MODE_PRIVATE)
        while(isRecording){
            var readSize=audioRecord.read(sData,0,sData.count())
            if(readSize>0){
                valveData —ByteArray=short2byte(sData)
                os.write(bData,0,readSize)
                os.flush()
            }
        }
        audioRecord.stop()
        os.flush()
        os.close()
    } catch(e:Exception){
        e.printStackTrace()
    }

android kotlin

2022-09-30 10:13

1 Answers

openFileOutput(file.absolutePath.replace("/", " ""), MODE_PRIVATE) was changed to FileOutputStream(file.absoluteFile), and it was written out.


2022-09-30 10:13

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.