请各位JAVA高手给予指教下面是我想出来的在文件内
找寻想要的字串并且统计次数~~~请问有人有更好更方便的方法
可以给予指点吗???
package IOTESTDemo;
import java.io.IOException;
import java.io.FileReader;
import java.io.IOException;
import java.util.*;
import java.util.Arrays;
import java.text.ParseException;
public class IODEMOTEST {
public static void main(String[] args) throws IOException
{
ArrayList<Integer> arrayList = new ArrayList<Integer>();
FileReader fr = new FileReader("fr.txt");
int counter=0;
System.out.println("请输入你要找寻的字串");
Scanner scanner = new Scanner(System.in);
String ST=scanner.nextLine();
char[] charArray = {'a', 'b', 'c', 'd', 'e'};
String str2 = new String(charArray);//把字符阵列转成字串
int[] chs = new int[30];
int ch;
int count=0;
while ((ch = fr.read()) != -1)
{
if ((ch != 32))
{
arrayList.add(ch);
if(ch==13)
{
arrayList.remove(arrayList.indexOf(13));
counter=counter+showString(arrayList,ST);
System.out.println("counter=="+counter);
}
if(ch==10)
{
arrayList.remove(arrayList.indexOf(10));
counter=counter+showString(arrayList,ST);
System.out.println("counter=="+counter);
}
} else
{
counter=counter+showString(arrayList,ST);
System.out.println("一共有"+counter+"字串相符合");
//
System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++");
}
}
fr.close();
}
//