java中的令牌解析 [英] token parsing in java

查看:83
本文介绍了java中的令牌解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个带有printStream对象的文件,如下所示。

I have created a file with printStream object as shown below.

PrintStream outPutOffice = new PrintStream(
   new BufferedOutputStream(new FileOutputStream(inDir+"/Office.txt")));
outPutOffice.print(fValue + (findx < agtOffColCount ? "|" : ""));   

现在我必须阅读内容并用|分隔它们的标记因为我用|写了标记分离。我已经编写了如下所示的代码,它将正确读取行,但不能使用|单独标记字符。

Now I have to read it content and separate it tokens with "|" as I have written token with "|" separated. I have write code as shown below it will read line correctly but not separate token with "|" character.

BufferedReader inPutAgent = new BufferedReader(
   new InputStreamReader(new FileInputStream(inDir+"/Office.txt")));

String column=inPutAgent.readLine();
String []columnDetail = column.split("|");

columndetail数组在每个索引中包含单个字符,而我想在每个索引中使用单个标记。

columndetail array contains single character in each index instead i want single token in each index.

有什么问题?

推荐答案

split 方法适用于正则表达式并且由于管道符号(|)具有特殊含义并且是保留的,您需要像这样转义:

the split method works with regular expressions and since the pipe symbol (|) has a special meaning and is reserved, you need to escape it like this:

split("\\|");

你应该阅读有关正则表达式的信息这里此处

You should read about regex here or here

这篇关于java中的令牌解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆