团队第二阶段个人冲刺day04

今天实现了从文本文件中读取停用词到数组中,

package shunxu;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class test {
public static String txt2String(File file){
StringBuilder result = new StringBuilder();
try{

InputStreamReader isr = new InputStreamReader(new FileInputStream(file), "UTF-8");
BufferedReader br = new BufferedReader(isr);//构造一个BufferedReader类来读取文件
String s = null;
while((s = br.readLine())!=null){//使用readLine方法,一次读一行
result.append(System.lineSeparator()+s);
}
br.close();
}catch(Exception e){
e.printStackTrace();
}
return result.toString();
}

public static void main(String[] args){
File file = new File("E:\\StopWords\\StopWords.txt");//我的txt文本存放目录,根据自己的路径修改即可

try{
String s = "";
InputStreamReader isr = new InputStreamReader(new FileInputStream("E:\\StopWords\\StopWords.txt"), "UTF-8");
BufferedReader in =new BufferedReader(isr);
while((s=in.readLine())!=null){
String[] split = s.split(",");
/*for(int i=0;i<split.length;i++)

{

System.out.println(split[i]);

}*/
}
}catch(FileNotFoundException e){
e.printStackTrace();
}
catch(IOException e){
e.printStackTrace();
}
}
}

posted @ 2021-06-04 16:19  小萌新一枚lll  阅读(21)  评论(0编辑  收藏  举报