如何在java中打印文件的第三列

时间:2014-10-29 08:53:12

标签: 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);
    }

第三栏是词干。怎么打印?

3 个答案:

答案 0 :(得分:1)

这里是代码:

String[] splitdata = filedata.split(" ");

String thirdcol = splitdata[2];

System.out.println(thirdcol);

希望它会对你有所帮助。

答案 1 :(得分:0)

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

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

答案 2 :(得分:0)

希望它会有所帮助

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);
}