简体   繁体   English

从网站查看大文本文件的最佳方法是什么?

[英]What is the best way to view large text files from websites?

I tried webview.loadurl("www.blahblah.com/blah.txt") and it crashed after a couple of seconds. 我尝试了webview.loadurl("www.blahblah.com/blah.txt") ,几秒钟后它崩溃了。 What else can I do? 我还可以做些什么?

I only want to view these .txt files from the web as fast and as stable as possible. 我只想尽可能快和稳定地从网络上查看这些.txt文件。

Also I came across asynctask while researching. 我在研究时也遇到了asynctask What is it and can it help me with this? 这是什么,它可以帮助我吗?

Also how can I make them to a string if I want to display these text files as a listview item? 另外,如果要将这些文本文件显示为列表视图项,如何将它们制成字符串?

Asynctask is wrapper for a new thread that allow you to perform network tasks such as downloading. Asynctask是新线程的包装,该线程允许您执行网络任务,例如下载。 If you try to download on the UI thread, you will get a crash. 如果您尝试在UI线程上下载,将会崩溃。

For the text file, download it to disc first, and then read it into memory and display it 对于文本文件,请先将其下载到光盘,然后将其读入内存并显示

StringBuilder txtString = new StringBuilder();

try {
    BufferedReader br = new BufferedReader(new FileReader(file));
    String textLine;

    while ((textLine = br.readLine()) != null) {
        txtString.append(line);
        txtString.append('\n');
    }
}
catch (IOException e) {
//error stuff
}

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

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