I am making an app which is reading the text file and display content into EditText, but I am facing one issue is that when the file is too large (which is more than 1mb) than setting text into EditText takes some time and app get stuck.
If anyone knows that is there any other option to display text into EditText then please help me. I got stuck over here
edittext.setText(text);//got stuck here
this readFile()
is inside AsyncTask
and setText()
is inside onPostExecute()
public String readFile(String fileName) {
StringBuilder builder = null;
BufferedReader reader = null;
try {
File file = new File(fileName);
if (!file.exists()) {
throw new RuntimeException("File not found");
}
reader = new BufferedReader(new FileReader(file));
builder = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
builder.append(line);
builder.append("\n");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return builder != null ? builder.toString() : "";
}
Edit
Now I am not using BufferedReader
to read a file. I am reading a file using c
code