62,628
社区成员
发帖
与我相关
我的任务
分享import java.io.*;
public class CountChar {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
FileReader fileIn=null;
try{
fileIn=new FileReader("D:\\java\\1.txt");
}catch(FileNotFoundException e){
System.out.println("找不到文件,程序将终止!");
e.printStackTrace();
System.exit(-1);
}
char[] cc=new char[1024];
try{
fileIn.read(cc);
}catch(IOException e){
System.out.println("文件读入错误!");
fileIn.close();
}
String str1=new String(cc);
String[] strArray=new String[1024];
strArray=str1.split(" to ");
int count=strArray.length;
System.out.println(""+count);
}
}
String str = "TO,to,toto,aaaaa,too,ato";
int times = str.length() - str.replaceAll("[To||to]","").length();
System.out.print("to出现的次数"+times/2);