下面是文本文件,我想以某种随机顺序在行中打印每个数字,以某种随机方式读取每行。我可以逐一读取每行,然后按顺序打印每行对应的数字,但是有什么方法可以以某种随机方式读取行,以便我可以按随机顺序打印所有数字。以随机的方式读取行,然后以随机顺序打印数字
Line1 1 1116 2090 100234 145106 76523
Line2 1 10107 1008 10187
Line3 1 10107 10908 1109
任何建议,将不胜感激。以下是我编写的代码将按顺序读取行。
BufferedReader br = null;
try {
String sCurrentLine;
br = new BufferedReader(new FileReader("C:\\testing\\Test.txt"));
while ((sCurrentLine = br.readLine()) != null) {
String[] s = sCurrentLine.split("\\s+");
for (String split : s) {
if(split.matches("\\d*"))
System.out.println(split);
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (br != null)br.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
1号线,将每个个体数是“1 ','1','1','6','2','0'等,还是'1116',2090','100234'等? – 2012-04-23 01:01:59
对于第1行,数字是 - ''1''1116''2090''100234''145106''76523''和对于第2行,数字是 - '''''10107''1008''10187'' – AKIWEB 2012-04-23 01:04:17