如何用java打印文件的第三列



我的文件包含Treetagger 输出的数据

    big  JJ big
    nice JJ nice
    full JJ full
    big  JJ big
   best JJS good

这是我的代码

    File f = new File(n[x]);
    BufferedReader br = new BufferedReader(new FileReader(f));
    String s;
    String filedata = "  ";
    while ((s = br.readLine()) != null) {
        filedata += s + " ";
    }
    StringTokenizer stk = new StringTokenizer(filedata, " ");
    while (stk.hasMoreTokens()) {
        String token = stk.nextToken("JJ");
        String[] to = token.split(" ", 2);
        String ft = to[1];
        a.write(ft);
    }

第三列是词干。如何打印?

这里的代码:

String[] splitdata = filedata.split(" ");
String thirdcol = splitdata[2];
System.out.println(thirdcol);

希望它能帮助你。

希望它能帮助

File f=new File(n[x]);
     BufferedReader br = new BufferedReader(new FileReader(f));
     String s;
     while((s=br.readLine())!=null){
String test = s.replace(" ","");
String[] test2 = test.split("JJ");
String test3 = test2[1];
System.out.println(test3);
}

String.split方法可用于将字符串分解为其基本令牌,并采用第三个:

String[] result = filedata.split(" ");
String col3 = result[2];

最新更新