Home > other >  Android File not Found Exception Kotlin
Android File not Found Exception Kotlin

Time:04-06

So I have a really simple project:

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
    val bundle = ActivityOptionsCompat.makeCustomAnimation(applicationContext, android.R.anim.fade_in, android.R.anim.fade_out).toBundle()
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
    val myObj = File("C:\\Users\\user\\Desktop\\k.txt")
    val myReader = Scanner(myObj)
}

and I have a "k.txt" file on my desktop. Whenever val myReader = Scanner(myObj) comes it throws a:

 Caused by: java.io.FileNotFoundException: C:\Users\user\Desktop\k.txt (No such file or directory)

why is that?

thanks for any help!

CodePudding user response:

You can't directly open or create file object from you local machine.

CodePudding user response:

You can not access storage computer

You coppy file in internal storage or external storage ( Phone Storage or SD card Storage)

Next step : Read file internal storage

Hope it`s fully

  • Related