Java 让文本查看器在android中更快地读取文件
我有一个简单的文本查看器类,可以打开文本文件并读取字符串。但问题是,当文件大于0.5Mb时,打开需要相当长的时间。有没有办法先加载小部件,然后再加载所有其他部件,或者有没有其他方法可以加快此过程?这是我的密码:Java 让文本查看器在android中更快地读取文件,java,android,string,text,bufferedreader,Java,Android,String,Text,Bufferedreader,我有一个简单的文本查看器类,可以打开文本文件并读取字符串。但问题是,当文件大于0.5Mb时,打开需要相当长的时间。有没有办法先加载小部件,然后再加载所有其他部件,或者有没有其他方法可以加快此过程?这是我的密码: InputStream inputStream = null; String str = ""; StringBuffer buf = new StringBuffer(); TextView txt = (TextView)findViewById(R.id.t
InputStream inputStream = null;
String str = "";
StringBuffer buf = new StringBuffer();
TextView txt = (TextView)findViewById(R.id.textView);
try {
inputStream = getContentResolver().openInputStream(uri);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
if (inputStream!=null) {
try {
while ((str = reader.readLine()) != null) {
buf.append(str + "\n");
}
} catch (IOException e) {
e.printStackTrace();
}
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
txt.setText(buf.toString());
}
}
尝试使用txt.append()?不,我怎么做?通过在chunkspost代码段中添加您的数据,您可以修改我的吗?或者创建一个,这样我就可以看到如何做到这一点?