zoukankan      html  css  js  c++  java
  • 团队第二阶段个人冲刺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();
    }
    }
    }

  • 相关阅读:
    单例模式
    二、CSS
    十一、多线程
    十二、协程
    十、多进程
    九、内存管理
    八、元类
    七、上下文管理器/魔术方法
    六、单例模式
    五、装饰器
  • 原文地址:https://www.cnblogs.com/lxywsx/p/14910634.html
Copyright © 2011-2022 走看看