Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何用java打印文件的第三列_Java - Fatal编程技术网

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

如何用java打印文件的第三列,java,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 = " ";

我的文件包含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);

希望它能对您有所帮助。

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

String[] result = filedata.split(" ");
String col3 = result[2];
希望能有所帮助

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[]to=token.split(“,2)如果将拆分次数限制为2,则应将其更新为3,或者忽略第二个参数。之后,您可以使用[2]获取第三个值,而不使用StringTokenizer。它已被弃用。您可以对字符串使用拆分。可能您使用的delimeter是附加字符串,但实际上不建议使用该字符串。我猜可能是使用
|
然后将字符串拆分为
|
delimeter@pyerwin它不工作第三列不是
splitdata[2]
splitdata吗?splitdata[0]是第一列,但[3]超出了b界限