我的文件名是:
20050701.txt
20050702.txt
20050703.txt
20050704.txt
20050705.txt
20050706.txt
20050707.txt
第一个文件内容是:
ST:20050701 000011 TI:20050719 000011 CN:06 LT:10 PN:13099885853 DN:1015902210 AR:D KC:- RS:@!!!!!!!
ST:20050701 000011 TI:20050719 000032 CN:06 LT:90 PN:13099885853 DN:1015902210 AR:D KC:* RS:@!!!!!!!
第二个文件内容是:
ST:20050702 000011 TI:20050719 000011 CN:06 LT:10 PN:13099885853 DN:1015902210 AR:D KC:- RS:@!!!!!!!
ST:20050702 000011 TI:20050719 000032 CN:06 LT:90 PN:13099885853 DN:1015902210 AR:D KC:* RS:@!!!!!!!
依次类推
我想用JAVA输入文件名,再查出文件里是LT:90的文件,
(就是我输入:20050701  
能打印出:ST:20050701 000011 TI:20050719 000032 CN:06 LT:90 PN:13099885853 DN:1015902210 AR:D KC:* RS:@!!!!!!!  这一条)
(输入:20050702  
能打印出:ST:20050702 000011 TI:20050719 000032 CN:06 LT:90 PN:13099885853 DN:1015902210 AR:D KC:* RS:@!!!!!!!  这一条)希望高手能给出源码,谢谢

解决方案 »

  1.   

    这个用java做有些复杂,你可以用word 宏来实现,自己试试看
      

  2.   

    import java.io.*;public class FindLine {
    private File file;
    private static final String toFind = "LT:90";

    /**
     * constructor
     * @param fpath the specified file (path)name
     */
    public FindLine(String fpath){
    file = new File(fpath);
    }


    /**
     * perform the function of finding the line which containing the specified
     * string
     * @param str the specified string contained in the line
     * @return the line that contains the specified str
     *  or null,if no line contains such string
     */
    public String find(String str){
    try{
    BufferedReader br = new BufferedReader(new FileReader(file));
    String tmp = new String();
    while((tmp=br.readLine())!=null){
    if(tmp.contains(str)){
    return tmp;
    }
    }
    }catch(IOException e){
    e.printStackTrace();
    }

    return null;
    }


    /**
     * performed the find function,the specified string is initialized to
     * "LT:90"
     * @return the line that contains the specified str
     *  or null,if no line contains such string
     */
    public String find(){
    return find(toFind);
    }

    /**
     * the main function
     * @param args ...
     */
    public static void main(String[] args){
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String name = new String();
    try{
    name = br.readLine();
    if(name.lastIndexOf(".txt")==-1){
    name += ".txt";
    }
    }catch(IOException e){
    e.printStackTrace();
    System.exit(1);
    }

    System.out.println(new FindLine(".\\"+name).find());
    }


    }