我有一个文件,其中包含来自不同推文的信息,由 \t 分隔。该信息包含字段用户、语言和文本。
我需要做的是将有关推文的信息存储在 ArrayList 或数组中,以便将每个单词分开,以便我可以遍历它们并进行比较。
这是文件的示例
@GracieWhitton  en  RT @GracieWhitton: I need 16 more followers to 2500. I know      you are out there!! Come on folks. :)
@SHARPErThnYu   en  RT @SHARPErThnYu: Stop texting me. Our relationship is non existent
@BraandiiSongz  fr  RT @BraandiiSongz: Le 1er rdv chui tj timide ac une grosse boule au ventre apr c autre chose
@BeyTomce   en  @BeyTomce Saturday ???
@VivoPorVoceLuaB    pt  @VivoPorVoceLuaB Segui,Sdv amore
@JamelTaylour   en  "@str8BappN: @JamelTaylour That go bruh"right on bro
@eluniweb   es  RT @eluniweb: #UCAB mañana martes 16 de abril hay clases  http://t.co/ZeUzGBM7MI
@MariAleAguirre es  RT @MariAleAguirre: Que CINISMO el de El Ciudadano en GLOBOTERROR. Esta diciendo que VTV fue el que llamo a la violencia en Altamira...  ...
这是我的代码,我不知道为什么它不能按我的意愿工作。我不知道如何迭代数据。
public Tweets() throws FileNotFoundException {
    Scanner in=new Scanner(new File("./twitter/data.txt"));
    ArrayList<ArrayList<String>> comments= new ArrayList<ArrayList<String>>();
    while(in.hasNext()){
        String line=in.nextLine();
        String[] data=line.split("\t",-1);
        ArrayList<String> words = new ArrayList<String>();
        words.add(data[0]);
        words.add(data[1]);
        String[] w=data[2].split(" ",-1);
        for(int i=0;i<w.length-1;i++)
        {
            words.add(w[i]);
        }
        comments.add(words);
    }
    in.close();
}