import java.io.*;public class Find1 {
public static void main(String[] args) {
if (args.length !=1) {
System.out.println("使用法:java Find1 检索文字列《检索对象文件》");
System.out.println("例:jfldsflkdsfjlsd");
System.out.exit(0);
}
String findsring=args[0];
System.out.println("检索文字列是["+findstring+"]");
BufferedReader Reader=new BufferedReader (new InputStreamReader(System.in),1);
try {
String line;
int linenum=1;
while ((line=Reader.readline())!=null) {
int n=line.indexof(findstring);
if (n>=0) {
System.out.println(linenum+":"+line);
}
linenum++;
}
}catch (IOException e) {
System.out.println(e);
}
}
}
public static void main(String[] args) {
if (args.length !=1) {
System.out.println("使用法:java Find1 检索文字列《检索对象文件》");
System.out.println("例:jfldsflkdsfjlsd");
System.out.exit(0);
}
String findsring=args[0];
System.out.println("检索文字列是["+findstring+"]");
BufferedReader Reader=new BufferedReader (new InputStreamReader(System.in),1);
try {
String line;
int linenum=1;
while ((line=Reader.readline())!=null) {
int n=line.indexof(findstring);
if (n>=0) {
System.out.println(linenum+":"+line);
}
linenum++;
}
}catch (IOException e) {
System.out.println(e);
}
}
}
System.exit(0);
while ((line=Reader.readLine())!=null) {
String findstring=args[0];
{
public static void main(String[] args)
{
if (args.length !=1)
{
System.out.println("使用法:java Find1 检索文字列《检索对象文件》");
System.out.println("例:jfldsflkdsfjlsd");
System.exit(0);
}
String findstring=args[0];
System.out.println("检索文字列是["+findstring+"]");
BufferedReader Reader=new BufferedReader (new InputStreamReader(System.in),1);
try
{
String line;
int linenum=1;
while ((line=Reader.readLine())!=null)
{
int n=line.indexOf(findstring);
if (n>=0)
{
System.out.println(linenum+":"+line);
}
linenum++;
}
}catch (IOException e) {System.out.println(e);}
}
}
BufferedReader是个类,
Reader也是个类,怎么可以这样声明呢!!!
System.out.exit(0);
应该是System.exit(0)。
第二个问题
BufferedReader Reader中的Reader是关键字,不能做用户变量。
System.out.exit(0);
这个地方,去掉这个就可以完全运行了。。呵呵。。谢谢大家哟public class Find1
{
public static void main(String[] args)
{
System.out.println("使用法:java Find1 检索文字列《检索对象文件》");
System.out.println("例:jfldsflkdsfjlsd");
String findstring=args[0];
System.out.println("检索文字列是["+findstring+"]");
BufferedReader sha=new BufferedReader (new InputStreamReader(System.in),1);
try
{
String line;
int linenum=1;
while ((line=sha.readLine())!=null)
{
int n=line.indexOf(findstring);
if (n>=0)
{
System.out.println(linenum+":"+line);
}
linenum++;
}
}catch (IOException e) {System.out.println(e);}
}
}