Back to project page prw.
The source code is released under:
Copyright (c) 2014, KB Sriram All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. R...
If you think the Android project prw listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package org.kbsriram.android.prw.data; //from w w w. ja v a 2 s. c om // This code will pull out a single line from a text file that contains // a bunch of lines. // // The first line in the text file is expected to be a number, with the // total number of lines in the file. import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; public class CSimpleLineDatabase { // given an index and a stream, this will return the (index mod // #lines) line within the file. eg: given a file with 5 lines // and an index 12, this will return the 3rd line in the // file. index 10 in the same file will give the first line in the // file. public final static String getLine(long index, InputStream in) throws IOException { BufferedReader br = null; try { br = new BufferedReader(new InputStreamReader(in), 8192); long max = Long.parseLong(br.readLine()); long actual = index % max; long cur = 0l; while (cur < actual) { br.readLine(); // skip past this many. cur++; } return br.readLine(); } finally { if (br != null) { try { br.close(); } catch (IOException ign) {} } } } }