String.contains function not working


I have to check whether the words from File1 exist in File2 or not
and then count. Data in both files is shown below.



The words in File1 are like shown below:




  1. 发表

  2. 发愁

  3. 发达

  4. 发抖

  5. 发挥



The data in File2 is like shown below:




  1. 这篇论文是什么时候发表的?

  2. 91 .数据 删掉 被马工程师 了

  3. 92 .驾驶 酒后 很大 危害

  4. 93 .客观地 要 他人 评价

  5. 94 .我不小心 水壶 打翻 了 把



The code I have written is as follows:



File file1 = new File("ChineseWord.txt");
Scanner sc = new Scanner(new FileInputStream(file1));
ArrayList<String> list = new ArrayList<String>();
ArrayList<String> newList = new
ArrayList<String>();

while(sc.hasNext()){
list.add(sc.next());
}

sc.close();

File file2 = new File("RandomData.txt");

Scanner newScanner = new Scanner(new FileInputStream(file2));

int count = 0;

for (int i = 0; i < list.size(); i++) {

while(newScanner.hasNext()){

String word = newScanner.nextLine();
String toMatch = list.get(i);

if(word.contains(toMatch)){
System.out.println("Success");
count++;
}


}

String test = list.get(i);
newList.add(test+"exists" + count+ "times");
count =0;

}


The question is that it returns 0 for all words whereas the very
first word in File1 exists in the very first line of File2. If I
manually do something like this



if(word.contains("发表")){
System.out.println("Success");
count++;
}


It prints successs otherwise it does not ? Why is this so?


- Technology - Languages
+ Webmasters
+ Development
+ Development Tools
+ Internet
+ Mobile Programming
+ Linux
+ Unix
+ Apple
+ Ubuntu
+ Mobile & Tablets
+ Databases
+ Android
+ Network & Servers
+ Operating Systems
+ Coding
+ Design Software
+ Web Development
+ Game Development
+ Access
+ Excel
+ Web Design
+ Web Hosting
+ Web Site Reviews
+ Domain Name
+ Information Security
+ Software
+ Computers
+ Electronics
+ Hardware
+ Windows
+ PHP
+ ASP/ASP.Net
+ C/C++/C#
+ VB/VB.Net
+ JAVA
+ Javascript
+ Programming
Privacy Policy - Copyrights Notice - Feedback - Report Violation 2018 © BigHow