0

I am trying to read lines of a file and putting values in a list but I keep getting an ENOENT. I use the relative file path. How should I correct this? Code:

val inputStream: InputStream = File("cards.txt").inputStream()
val lineList = mutableListOf<String>()
inputStream.bufferedReader().forEachLine { lineList.add(it) }
lineList.forEach{println(">  " + it)}

Error:

android.system.ErrnoException: open failed: ENOENT (No such file or directory)
Mingdi
  • 185
  • 1
  • 2
  • 7
  • Hi, interesting, perhaps the file isn't readable? – IronMan Jul 09 '20 at 21:47
  • Check if the file even exists. – Abbas Jul 09 '20 at 21:48
  • ENOENT means that the os can't find the directory for the file. Please provide more information about the directories. Have you checked your current working directory, and if it does exit? – SmileDeveloper Jul 09 '20 at 21:50
  • IronMan Abbas yes it exists is in my project folder and is readible. It is a txt file – Mingdi Jul 09 '20 at 21:52
  • SmileDeveloper it says the current working directory is just / – Mingdi Jul 09 '20 at 22:00
  • `"cards.txt"` is not a valid filesystem path. "it exists is in my project folder" -- then it is not on the device. If you want to pre-package a text file with your app, put it [in an `assets/` folder](https://stackoverflow.com/a/18302624/115145), and use `AssetManager` to read in its contents. – CommonsWare Jul 09 '20 at 23:00

0 Answers0