为什么 word.compareToIgnoreCase(s) == 0 就可以有true,word == s.toLowerCase();就全为false
strss是包含to的一串字符句子;
public class THREAD_NOTE {
public static void main(String[] args) {
String word = "to";
String[] strs = {"E:\\java\\newjava\\图片\\t1.txt",
"E:\\java\\newjava\\图片\\t2.txt",
"E:\\java\\newjava\\图片\\t3.txt",
"E:\\java\\newjava\\图片\\t4.txt"};
Path[] ps = new Path[strs.length];
for(int i=0;i<strs.length;i++) {
ps[i] = Paths.get(strs[i]);
}
Collection<Path> p= Arrays.asList(ps);
Set<Path> paths = new HashSet<>(p);
for(Path path:paths) {
int count = 0,sum = 0;double countd = 0;
try (BufferedReader br = new BufferedReader(new FileReader(path.toString()));)
{
String str = br.readLine();
while(str != null) {
String[] strss = str.split("[ ,.:;\"]");
sum += strss.length;
for(String s:strss) {
if(word.compareToIgnoreCase(s) == 0)
count += 1;
}
str = br.readLine();
}
//countd = (double)((count/sum)*100);
System.out.println((count*1.0/sum));
}catch(Exception e) {e.printStackTrace();}
}
}
}