java程序求助

来源:百度知道 编辑:UC知道 时间:2024/06/27 13:48:52
分析下面程序需求,设计程序流程图,并写一段程序完成下面功能.
1.从控制台接受用户输入的文件名和待查找字符串参数.
2.打开用户输入文件名对应的文本文件,查找用户输入字符串在文件中出现的全部位置(需要给出字符串出现的行和列)并输出到控制台上.
例如:
文件(test.txt)内容:
java is a good language
we have study how to read and write file in java
程序运行:
请输入文件名:
test.txt

注:如果一时间不能给出完整的答案,能回答出大部分的内容都可以.

import java.io.*;
import java.lang.Exception;

public class Search
{
String context;
int lenth[]=new int[50],row,line;

public Search(){}

public void openFile(String file_name) throws Exception{
String stri="",str;
File fl=new File(file_name);
FileReader reader=new FileReader(fl);
BufferedReader in = new BufferedReader(reader);
int i=0;
while((str=in.readLine())!=null){
stri+=str;
lenth[i++]=str.length();
}
System.out.println(stri);
context=stri;

}

public void lookup(String words){
int flag=0,i=0,len;
len=words.length();
flag=context.indexOf(words,i);
while(flag!=-1){
i=i+len;
getPos(flag);

flag=context.indexOf(words,i);
}
}

public