I am making a dictionary application on Android. During startup, the application will download the contents of the .index file (~ 2 MB, 100,000 lines)
However, when I use BufferedReader.readLine () and do something with the returned string, the application calls OutOfMemory.
// Read file snippet Set<String> indexes = new HashSet<String)(); FileInputStream is = new FileInputStream(indexPath); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); String readLine; while ( (readLine = reader.readLine()) != null) { indexes.add(extractHeadWord(readLine)); } // And the extractHeadWord method private String extractHeadWord(String string) { String[] splitted = string.split("\\t"); return splitted[0]; }
When reading the log, I found that when executed, it forces the GC to explicitly clean objects repeatedly (GC_EXPLICIT releases xxx objects in which xxx is a large number, such as 15000, 20000).
And I tried another way:
final int BUFFER = 50; char[] readChar = new char[BUFFER];
.. and it works very fast. But that was not quite what I wanted.
Is there any solution that works fast as a second snippet and is easy to use as a first?
Regard.
source share