简体   繁体   English

Android-从外部存储读取大文件

[英]Android - Read big file from external storage

If I have to read a big file from a external storage, such as SDCard, I know i should do it in a separate thread, but my question is: If I do so on the main thread, will it cause a exception similar to "NetworkOnMainThreadException"? 如果我必须从外部存储设备(例如SDCard)读取大文件,我知道我应该在单独的线程中执行此操作,但是我的问题是:如果我在主线程上执行此操作,是否会导致类似于“ NetworkOnMainThreadException“?

I know that Network exception will always happen, but I imagine that if the read is too long, something my cause a exception or maybe cause android to shut the app down... 我知道网络异常总是会发生,但是我想如果读取时间太长,则可能导致我异常或导致android关闭应用程序...

I'm asking this because right now I'm unable to test it since my android device does not have a external storage and my dev machine is SSD (which speed things up a lot...) 我问这个问题是因为现在我无法测试它,因为我的android设备没有外部存储,而我的开发机是SSD(这大大加快了速度...)

Details: 细节:
- In real scenario, the files can be as big as a couple of GB... -在实际情况下,文件可以大到几个GB。

No you won't get an exception if you are using straight file input streams, but you will probably get an ANR. 不,如果您使用的是直接文件输入流,则不会出现异常,但是您可能会得到ANR。 This allows the user to then kill the process and exit your application. 这样,用户可以终止进程并退出您的应用程序。

http://developer.android.com/training/articles/perf-anr.html http://developer.android.com/training/articles/perf-anr.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM