Created
February 28, 2014 23:21
-
-
Save rayjcwu/9282061 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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