Joke Collection Website - Blessing messages - Write a program in Java to find out the number of occurrences of the string "mobnet" from a file (c:\test.txt)?
Write a program in Java to find out the number of occurrences of the string "mobnet" from a file (c:\test.txt)?
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class TxtCount {
/**
* @param args
* /
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new FileReader("C:\\test.txt"));< /p>
StringBuilder sb = new StringBuilder();
while (true) {
String str = br.readLine();
if (str == null)
break;
sb.append(str);
}
Pattern p = Pattern.compile ("mobnet");
Matcher m = p.matcher(sb);
int count = 0;
while(m.find()) {
count++;
}
System.out.println("mobnet-*** appeared" + count + "times");
p>
}
}
- Related articles
- How do I change my ticket?
- What is a short message with connection?
- How about M blue mobile phone? Is it worth buying?
- How to send short messages to PHS
- C9 Zhejiang 2023 Admission Big Data is coming! A total of 47 14 people were on the list. Did you accept it?
- Can Apple 13 see the intercepted messages?
- How to chase girls by SMS
- How to send a notice of love donation when the family members of class children die?
- Mobile phone short number problem
- How to send short messages in the United States and China is more cost-effective?