Note that there are some explanatory texts on larger screens.

plurals
  1. PONeed a better method of reading and storing values from text file
    text
    copied!<p>Goal: to get values from a text file and store it into values to load into my sqlite database.</p> <p>Problem: My method is not efficient, and I need help comming up with an easier way.</p> <p>As of right now I am parsing my textfile that looks like this.</p> <pre><code>agency_id,agency_name,agency_url,agency_timezone,agency_lang,agency_phone 1,"NJ TRANSIT BUS","http://www.njtransit.com/",America/New_York,en,"" 2,"NJ TRANSIT RAIL","http://www.njtransit.com/",America/New_York,en,"" </code></pre> <p>I am parsing everytime i read a comma, then storing that value into a variable, then I will use that variable as my database value.</p> <p>This method works and is time consuming, The next text file I have to read in has over 200 lines of code, and i need to find an easier way.</p> <pre><code>AgencyString = readText(); tv = (TextView) findViewById(R.id.letter); tv.setText(readText()); StringTokenizer st = new StringTokenizer(AgencyString, ","); for (int i = 0; i &lt; AgencyArray.length; i++) { size = i; // which value i am targeting in the textfile //ex. 1 would be agency_id, 2 would be agency_name AgencyArray[i] = st.nextToken(); } tv.setText(AgencyArray[size]); //the value im going to store into database value } private String readText() { InputStream inputStream = getResources().openRawResource(R.raw.agency); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); int i; try { i = inputStream.read(); while (i != -1) { byteArrayOutputStream.write(i); i = inputStream.read(); } inputStream.close(); } catch (IOException e) { e.printStackTrace(); } return byteArrayOutputStream.toString(); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload