java中的令牌解析

lak*_*man 1 java

我用printStream对象创建了一个文件,如下所示.

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

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

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

String column=inPutAgent.readLine();
String []columnDetail = column.split("|");
Run Code Online (Sandbox Code Playgroud)

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

问题是什么?

Tim*_*the 6

分割方法适用于正则表达式和自管道符号(|)具有特殊含义,是保留,你需要逃避它是这样的:

split("\\|");
Run Code Online (Sandbox Code Playgroud)

你应该在这里这里阅读正则表达式