读取TXT每行文件打乱顺序。

917 查看

 import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;

 public class TxtLoad {
     public static void main(String[] args) {
         try {
             String uri = "X:\\file.txt";
             List<String> list = new ArrayList<String>();
             File file = new File(uri);
             FileInputStream fis = new FileInputStream(file);
             InputStreamReader isr = new InputStreamReader(fis);
             BufferedReader br = new BufferedReader(isr);
             String str = "";
             while ((str=br.readLine()) != null) {
                 list.add(str);
             }
             Collections.shuffle(list);
         } catch (FileNotFoundException e) {
             e.printStackTrace();
         } catch (IOException e) {
             e.printStackTrace();
         }
     }
 }