請各位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();
}
//