我必须在哪里将txt文件放入Android Studio? [英] Where do I have to put my txt file in Android Studio?

查看:635
本文介绍了我必须在哪里将txt文件放入Android Studio?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从txt读取文件,但是它抛出FileNotFoundException

I'm trying to read a File from txt, but it's throwing a FileNotFoundException

我已经将它放在资产文件夹和app文件夹中,但是仍然存在例外

I already put it in the assets folder, and in the app folder but the exception is still there

这就是我要使用的:

var asd=readFileAsLinesUsingReadLines("goodstops.txt")

fun readFileAsLinesUsingReadLines(fileName: String): List<String>
            = File(fileName).readLines()

推荐答案

我已经将它放在资产文件夹中

I already put it in the assets folder

Context上使用getAssets()获得AssetManager.调用AssetManager上的open("goodstops.txt")以获得InputStream,用于读取资产的内容.

Use getAssets() on a Context to get an AssetManager. Call open("goodstops.txt") on the AssetManager to get an InputStream to use for reading in the contents of the asset.

这篇关于我必须在哪里将txt文件放入Android Studio?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆