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));
{
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));
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());
}
}
如果每文件里有很多LT:90,都想查出来怎么该呢,帮忙指点一下,谢谢了
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());
}
}
1.5一下的可以把<String>去掉