【发布时间】:2014-08-26 10:31:37
【问题描述】:
我有一个文本文件,其值如下:
[2014-08-19 00:00:21,702] REC|SRC:923142676343|DST:9900|CNT:1|OPR:zong|\nADD BBCLANDAN\n
[2014-08-19 00:01:02,958] REC|SRC:923138824807|DST:9900|CNT:1|OPR:zong|ADD TRIXXS
[2014-08-19 00:01:12,799] REC|SRC:923125473547|DST:9900|CNT:1|OPR:zong|ADD SahafatMedia
[2014-08-19 00:01:32,894] REC|SRC:923142676343|DST:9900|CNT:1|OPR:zong|ADD BBCMEDIA\n\n
[2014-08-19 00:02:42,754] REC|SRC:923119511824|DST:9900|CNT:1|OPR:zong|ADD sMs
[2014-08-19 00:01:43,753] REC|SRC:923119511824|DST:9900|CNT:1|OPR:zong|ADD RIDAsMs
我已经阅读了文本文件并将其存储到带有输出的数组列表中:
输出:
923119511824|DST:9900|CNT:1|OPR:zong|ADD RIDAsMs
923119511824|DST:9900|CNT:1|OPR:zong|ADD sMs
923125473547|DST:9900|CNT:1|OPR:zong|ADD SahafatMedia
923138824807|DST:9900|CNT:1|OPR:zong|ADD TRIXXS
923142676343|DST:9900|CNT:1|OPR:zong|ADD BBCMEDIA\n\n
923142676343|DST:9900|CNT:1|OPR:zong|\nADD BBCLANDAN\n
[2014-08-19 00:01:02,958] REC|
[2014-08-19 00:01:12,799] REC|
[2014-08-19 00:01:32,894] REC|
[2014-08-19 00:01:43,753] REC|
[2014-08-19 00:02:42,754] REC|
[2014-08-19 00:00:21,702] REC|
现在我想标记这个数组列表以仅显示输出中的重复联系人号码,例如 923142676343 及其在 ADD 之后的内容,例如 TRIXXS 我需要帮助吗???
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
public class pring
{
public static final String FILE_LOCATION = "C:/Users/DfroJaCk DB/Desktop/zongrecv.txt";
public static void main ( String [ ] args )
{
//Your reader
BufferedReader in = null;
//Where you store the Strings
ArrayList < String > al = new ArrayList < String > ();
try
{
//Open the file and give it to the reader
in = new BufferedReader ( new FileReader ( FILE_LOCATION ) );
String line;
//As long as the file has more lines read a line at a time
while ( ( line = in.readLine () ) != null )
{
//Split the line and stoe it in an array
String [ ] splitLine = line.split ( "SRC:" );
for ( int i = 0; i < splitLine.length; i++ )
{
//Add each element of the split array into an ArrayList
al.add ( splitLine [ i ] );
}
}
//Catch your possible problems
} catch ( FileNotFoundException fnfe )
{
fnfe.printStackTrace ();
} catch ( IOException ioe )
{
ioe.printStackTrace ();
}
//Sort your list
Collections.sort ( al );
for ( String s : al )
{
//spit it out
System.out.println ( s );
}
}
}
【问题讨论】:
标签: java arraylist stringtokenizer