Skip to content

Instantly share code, notes, and snippets.

@rayjcwu
Created February 28, 2014 23:21
Show Gist options
  • Select an option

  • Save rayjcwu/9282061 to your computer and use it in GitHub Desktop.

Select an option

Save rayjcwu/9282061 to your computer and use it in GitHub Desktop.
public String returnOneLine(String filename) throws IOException {
BufferedReader br = new BufferedReader(new FileReader(filename));
String result = br.readLine();
String tmp = null;
int size = 2;
while ((tmp = br.readLine()) != null) {
int i = (int)(Math.random() * size++);
if (i < 1) {
result = tmp;
}
}
br.close();
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment