package p3;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Scanner;
import java.util.Set;
public class splitWords
{
static HashMap<String, Integer > hashMap=new HashMap<String,Integer>();
public static void main(String[] args) throws FileNotFoundException
{
splitWords sw=new splitWords();
sw.count("D:/word.txt");
//sw.count("D:/io.txt");
sw.result();
}
public void count(String src) throws FileNotFoundException {
File file=new File(src);
if(!file.exists())
{
System.out.println("文件不存在");
return;
}
Scanner scanner=new Scanner(file);
System.out.println(src+"----------------中的文章内容-------------------");
while(scanner.hasNextLine())
{
String line=scanner.nextLine();
System.out.println(line);
//\w+ : 匹配所有的单词
//\W+ : 匹配所有非单词
String[] lineWords=line.split("\\W+");//用非单词符来做