【发布时间】:2015-03-20 22:32:51
【问题描述】:
我有一个在大型机 z/os 上运行的 java 程序,它正在读取一个 EBCDIC 文件。文件中的几行有多个由 EBCDIC 'LF' X'025' 分隔的记录。我正在使用 Java readline 并且正如预期的那样,它正在读取记录直到换行并丢弃其余记录。除了将大行解析为多条记录外,还有什么方法可以使读取方法将行拆分为多条/记录并返回相同的内容?如果需要,我可以选择将换行符更改为任何值。
输入:
10,IBM,ERWIN,BLACK,123,ABC(LF)10,IBM,JACK,ROSE,456
预期输出
10,IBM,ERWIN,BLACK,123,ABC
10,IBM,JACK,ROSE,456
当前代码:
public ArrayList<String> readMainframeFile()
{
//String DDNAME = ZFile.allocDummyDDName();
//System.out.println("The DDName is " + DDNAME);
//ZFile convout = new ZFile("//DD:CONVOUT", "wb,type=record,noseek");
//RecordReader reader=null;
try {
ZFile convin = new ZFile("//DD:CONVIN", "rb,type=record,noseek");
System.out.println("The DDName is" + convin.getLrecl());
byte[] recordBuf = new byte[convin.getLrecl()];
int bytesRead=0;
InputStream ins = null;
BufferedReader reader = null;
String temp=null;
ArrayList<String> lines = new ArrayList<String>();
while((bytesRead = convin.read(recordBuf)) > 0) {
//System.out.println("The number of bytes read is" + bytesRead);
try {
ins = new ByteArrayInputStream(recordBuf);
reader = new BufferedReader(new InputStreamReader(ins,Charset.forName("ibm500")));
temp=reader.readLine();
lines.add(temp);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
return lines;
} catch (ZFileException e) {
System.err.println(e.getMessage());
return null;
}
}
【问题讨论】:
-
分割线的基本标准是什么?我猜是
(LF) -
你应该循环
readLine()直到它返回null。您在构建ByteArrayInputStream.时也忽略了bytesRead