import java.io.*;
import java.util.*;public class TelNumStore
{
private Collection c1,c2;
private static final String STR = "LT:90";
private HashSet<String> telNumSet;
public TelNumStore(String file1, String file2)
{
telNumSet = new HashSet<String>();
c1 = new FindLine(file1).find();
c2 = new FindLine(file2).find();
}
public void storeTelnum(String file) { FileOutputStream fos=null;
try
{
fos = new FileOutputStream(new File("e:\\"+file));
}
catch(IOException e)
{
e.printStackTrace();
}
findTelNum(c1);
findTelNum(c2);
System.out.println(telNumSet);
Iterator it = telNumSet.iterator();
while(it.hasNext())
{
String str = (String)it.next();
try
{
fos.write(str.getBytes(),0,str.getBytes().length);
fos.write((byte)'\t');
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
public void findTelNum(Collection c)
{
Iterator it = c.iterator();
while(it.hasNext())
{
StringTokenizer st = new StringTokenizer((String)it.next()," ");
while(st.hasMoreTokens())
{
String str = st.nextToken();
if(str.contains("PN:"))
{
telNumSet.add(str);
}
}
}
}
public static void main(String args[])
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String file1 = "";
System.out.print("开始日期:");
System.out.println(file1);
try
{
file1 = br.readLine();
if(file1.lastIndexOf(".txt")==-1)
{
file1 += ".txt";
}
}
catch(IOException e)
{
e.printStackTrace();
System.exit(1);
}
String file2 = "";
System.out.print("结束日期:");
try
{
file2 = br.readLine();
if(file2.lastIndexOf(".txt")==-1)
{
file2 += ".txt";
}
}
catch(IOException e)
{
e.printStackTrace();
System.exit(1);
}
String fileStore = "";
System.out.print("存储的文件名:");
try
{
fileStore = br.readLine();
if(fileStore.lastIndexOf(".txt")==-1)
{
fileStore += ".txt";
}
}
catch(IOException e)
{
e.printStackTrace();
System.exit(1);
}
new TelNumStore(file1,file2).storeTelnum(fileStore);
}
}
文件名20050701.TXT....
文件内容
ST:20050701 005509 TI:20050701 005509 CN:20 LT:10 PN:13464213270 DN:1015902210 AR:A KC:-
ST:20050701 005509 TI:20050701 005548 CN:20 LT:90 PN:13464210723 DN:1015902210 AR:D KC:-
...............
我想再加一个输入判断条件,就是AR:的类别,A-Z的
就是我输入,两个文件名,还有AR后面的字母,根据这几个查出 PN:13464210723
现在程序的问题是,不能查两个文件之间的内容,而是只查输入的那两个文件,然后是没有AR条件判断,希望高手能给改改,谢谢
import java.util.*;public class TelNumStore
{
private Collection c1,c2;
private static final String STR = "LT:90";
private HashSet<String> telNumSet;
public TelNumStore(String file1, String file2)
{
telNumSet = new HashSet<String>();
c1 = new FindLine(file1).find();
c2 = new FindLine(file2).find();
}
public void storeTelnum(String file) { FileOutputStream fos=null;
try
{
fos = new FileOutputStream(new File("e:\\"+file));
}
catch(IOException e)
{
e.printStackTrace();
}
findTelNum(c1);
findTelNum(c2);
System.out.println(telNumSet);
Iterator it = telNumSet.iterator();
while(it.hasNext())
{
String str = (String)it.next();
try
{
fos.write(str.getBytes(),0,str.getBytes().length);
fos.write((byte)'\t');
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
public void findTelNum(Collection c)
{
Iterator it = c.iterator();
while(it.hasNext())
{
StringTokenizer st = new StringTokenizer((String)it.next()," ");
while(st.hasMoreTokens())
{
String str = st.nextToken();
if(str.contains("PN:"))
{
telNumSet.add(str);
}
}
}
}
public static void main(String args[])
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String file1 = "";
System.out.print("开始日期:");
System.out.println(file1);
try
{
file1 = br.readLine();
if(file1.lastIndexOf(".txt")==-1)
{
file1 += ".txt";
}
}
catch(IOException e)
{
e.printStackTrace();
System.exit(1);
}
String file2 = "";
System.out.print("结束日期:");
try
{
file2 = br.readLine();
if(file2.lastIndexOf(".txt")==-1)
{
file2 += ".txt";
}
}
catch(IOException e)
{
e.printStackTrace();
System.exit(1);
}
String fileStore = "";
System.out.print("存储的文件名:");
try
{
fileStore = br.readLine();
if(fileStore.lastIndexOf(".txt")==-1)
{
fileStore += ".txt";
}
}
catch(IOException e)
{
e.printStackTrace();
System.exit(1);
}
new TelNumStore(file1,file2).storeTelnum(fileStore);
}
}
文件名20050701.TXT....
文件内容
ST:20050701 005509 TI:20050701 005509 CN:20 LT:10 PN:13464213270 DN:1015902210 AR:A KC:-
ST:20050701 005509 TI:20050701 005548 CN:20 LT:90 PN:13464210723 DN:1015902210 AR:D KC:-
...............
我想再加一个输入判断条件,就是AR:的类别,A-Z的
就是我输入,两个文件名,还有AR后面的字母,根据这几个查出 PN:13464210723
现在程序的问题是,不能查两个文件之间的内容,而是只查输入的那两个文件,然后是没有AR条件判断,希望高手能给改改,谢谢
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货