我有星 * 分隔符文件,最后我需要在拆分 * 分隔符后存储在数组中,它在数组中存储值并打印列,但是它不断地一次又一次地打印相同的列值。
注意:txt 文件中有 60 列。
以下是我的代码:
static String[] arraylist;
String st;
BufferedReader Br = null;
File objFile = new File("C://DATA//File.txt");
Br = new BufferedReader(new FileReader(objFile));
LineNumberReader lineNumberReader = new LineNumberReader(new FileReader(objFile));
lineNumberReader.skip(Long.MAX_VALUE);
int lines = lineNumberReader.getLineNumber();
System.out.println("Total Rows in the File : " + lines);
List<String> lis = new ArrayList<String>();
while ((st = Br.readLine()) != null) {
arraylist = st.split("\\*");
for (int i = 0; i < arraylist.length; i++) {
lis.add(arraylist[1]);
lis.add("\n");
System.out.println("List value are " +lis);
}
}
Br.close();
以下是列示例:(此文件中同样有 60 列)
*ABC*08*31444*XYZ*1234*OLNBHJK*^TGJF54DFG908
*ABC*08*66657*XYZ*1234*OLNBHJK*^TGJF54DFG908
*ABC*08*33161*XYZ*1234*OLNBHJK*^TGJF54DFG908
*ABC*08*55771*XYZ*1234*OLNBHJK*^TGJF54DFG908
*ABC*08*20605*XYZ*1234*OLNBHJK*^TGJF54DFG908
*ABC*08*26471*XYZ*1234*OLNBHJK*^TGJF54DFG908
*ABC*08*85608*XYZ*1234*OLNBHJK*^TGJF54DFG908
*ABC*08*57735*XYZ*1234*OLNBHJK*^TGJF54DFG908
*ABC*08*46844*XYZ*1234*OLNBHJK*^TGJF54DFG908
*ABC*08*57823*XYZ*1234*OLNBHJK*^TGJF54DFG908
*ABC*08*31249*XYZ*1234*OLNBHJK*^TGJF54DFG908
*ABC*08*32394*XYZ*1234*OLNBHJK*^TGJF54DFG908
*ABC*08*46166*XYZ*1234*OLNBHJK*^TGJF54DFG908
*ABC*08*46167*XYZ*1234*OLNBHJK*^TGJF54DFG908
*ABC*08*43108*XYZ*1234*OLNBHJK*^TGJF54DFG908
*ABC*08*43110*XYZ*1234*OLNBHJK*^TGJF54DFG908
我只想打印第二列一次:例如:
ABC
ABC
ABC
ABC
ABC
ABC
ABC
ABC
ABC
ABC
ABC
ABC
ABC
ABC
ABC
ABC