import java.io.*;public class chaxun5 
{
private File file;
private static final String toFind = "LT:90";
public String FindLine(String fpath) {
file = new File(fpath);
return fpath;
} 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;
} public String find()
{
return find(toFind);
}
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("c:\\hkl\\logs\\"+name));
}
}错误是
chaxun5.java:66:cannot find symbol
symbol :class FindLine
location:class chaxun5
                    System.out.println(new FindLine("c:\\hkl\\logs\\"+name));

解决方案 »

  1.   

    if(tmp.contains(str)) 没有contains(String)这个方法System.out.println(new FindLine("c:\\hkl\\logs\\"+name)); 找不到 FindLine这个类
      

  2.   

    package file;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());
    }


    }
      

  3.   

    楼主把我的类名改了,把我的构造函数改成一般函数(一点功能都没有),main函数里还要new我的类,怎么可能通过呢?而且你又没有参数为String的构造函数
      

  4.   

    believefym(feng)
    如果每文件里有很多LT:90,都想查出来怎么该呢,帮忙指点一下,谢谢了
      

  5.   

    那你find的时候不要直接return tmp了,放到一个ArrayList之类的Collection里面,然后返回这个Collection就可以了
      

  6.   

    import java.io.*;
    import java.util.*;public class FindLine {
    private File file;
    private static final String TOFIND = "LT:90";
    private Collection <String>result;

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


    /**
     * 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 Collection 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;
    result.add(tmp);
    }
    }
    }catch(IOException e){
    e.printStackTrace();
    }

    return result;
    }


    /**
     * 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 Collection 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();
    System.out.print("intput the file name: ");
    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());
    }


    }
      

  7.   

    以上是jdk1.5的写法
    1.5一下的可以把<String>去掉