Monday, July 21, 2014

Load a file and print out lines in a random order


 public static void main(String args[]) throws IOException{
  List<String> lines = Files.readAllLines(Paths.get("test.txt"));
  Random r = new Random();
  while(!lines.isEmpty()){     
   String nextLine = lines.get(r.nextInt(lines.size()));
   System.out.println(nextLine);
   lines.remove(nextLine);   
  }  
 }