• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps How to read large txt file in android?

Koltis

Lurker
May 23, 2011
1
0
hi
I have text file with 65536 hex words (0,5MB) in sdcard (simulator)
Code:
13FC, ECFD, E842, EBD7, 959D, 11E4, EF68, 7BCB, 2B72, 33C5, 1271, 8053, 9608, 3A82, A766, B80A, ...
and i am trying to read it like this:


Code:
                          String[] loadFile(final String f) {
                              
                              String thisLine;
                              String help[] = null;
                              final List<String> s = new ArrayList<String>();
                              BufferedReader br = null;
                              try {
                                      br = new BufferedReader(new FileReader(f));
                                      while ((thisLine = br.readLine()) != null){
                                          help=thisLine.split(",");
                                          for(int i=0;i<16;i++){
                                               s.add(help[i]);
                                          }}
                                             
                              } catch (IOException ioe) {
                                      System.err.println("Error reading file " + f);
                                      throw new RuntimeException(ioe);
                              } finally {
                                      if(br!=null) try {
                                              br.close();
                                      } catch (IOException e) {
                                              e.printStackTrace();
                                      }
                              }
                             
                              return s.toArray(new String[s.size()]);
                             
                      }
but this completly freezing my simulator for a few minutes. Is there any better way to get this values?

later in code when i am reading this string array containing file i use:


String value = sbox1[y]; //string[] array with file
wynik=Integer.valueOf(value, 16).intValue();
return w;
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones