是否可以使用Java将EBCDIC Comp-3文件转换为ASCII文件值? [英] Is this possible to convert EBCDIC Comp-3 file to ASCII file values using java?

查看:80
本文介绍了是否可以使用Java将EBCDIC Comp-3文件转换为ASCII文件值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将EBCDIC COMP-3字段转换为ASCII值,但是不起作用.但是二进制COMP-3字段可以转换为ASCII值.请帮助我了解这是否可行?我什至可以使用其他Java库也可以.我尝试并搜索了但没有具体答案.

I am trying to convert the EBCDIC COMP-3 fields to ASCII values but which is not working.But Binary COMP-3 fields could be converted to ASCII values.Please help me to understand is this possible or not? Even using any other java library is ok for me.I tried and searched may but no concrete answer I could see.

更新:

在我之前的一个二进制文件中应该是可以使用的二进制文件.我收到了答复,但是关于EBCDIC COMP-3的内容并不清楚.

In my previous one binary should be the one which will work.This what I received as answer but there was no clarity about EBCDIC COMP-3.

COPYBOOK:

001700 01 EMP-RECORD.                                                           
001900        10  EMP-NO                     PIC 9(10).                         
002000        10  EMP-NAME                   PIC X(30).                         
002100        10  EMP-ADDRESS                PIC X(30).                         
002200        10  EMP-SALARY                 PIC S9(8)V9(2) COMP-3.             
002200        10  EMP-ZIPCODE                PIC 9(4).                          

BINARY COMP-3文件:可以转换

  ËÍ>ÁÁ% ,Í_/Ê Ê                Â/>Å/%?ÊÁ                        Á~                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           ¢|ëá&ç                        ïçñèá ãñá<à                     ÊÊ>     

EBCDIC COMP-3:无法转换

0000001001suneel kumar r                city                       e¡5671   

程序:

public static void main(String args[]) throws Exception {
    String salesFile = "empcompnewbinary.txt";
    String copybookName = "EMPCOPYBOOK.txt";
    AbstractLine saleRecord;

    int fileStructure = Constants.IO_FIXED_LENGTH;
    CobolIoProvider ioProvider = CobolIoProvider.getInstance();
    AbstractLineReader reader = ioProvider.getLineReader(fileStructure, Convert.FMT_MAINFRAME,
            CopybookLoader.SPLIT_NONE, copybookName, salesFile);

    while ((saleRecord = reader.read()) != null) {
        System.out.print(saleRecord.getFieldValue("EMP-NO").asString() + "-"
                + saleRecord.getFieldValue("EMP-NAME").asString() + "-"
                + saleRecord.getFieldValue("EMP-ADDRESS").asString() + "-"
                + saleRecord.getFieldValue("EMP-SALARY").asDouble() + "-"
                + saleRecord.getFieldValue("EMP-ZIPCODE").asString());
    }
    reader.close();
}

推荐答案

没有"EBCDIC COMP-3字段"之类的东西,并且在ASCII码点中也没有等效的东西.它是二进制格式.因此,请理解您有字符和二进制格式的混合记录.

There is no such thing as an "EBCDIC COMP-3 field", and it has no equivalent in ASCII code points. It is a binary format. So understand you have a record mixed of character and binary formats.

Comp-3用十进制包装.在不同的计算机体系结构上,它们将符号小节放在何处以及在什么地方都可能有所不同,但是它是二进制格式,因此任何使用字符集规则进行转换的尝试都将始终失败.

Comp-3 is packed decimal. It can vary a bit on different machine architectures as to where they put the sign nibble and whatnot, but it is a binary format, so any attempt to convert it using character set rules will always fail.

到目前为止,处理此问题最简单的方法是将所有压缩的十进制数据转换为由字符组成的显示格式.因此,您实际上将其转换为c'01234.56',而不是x'0123456C',然后将标准EBCDIC转换为ASCII即可正常工作.

The easiest way to deal with this, by far, is to convert any packed decimal data to a display format, made up of characters. So instead of x'0123456C', you actually convert that to c'01234.56', and then your standard EBCDIC to ASCII conversion will work fine.

这篇关于是否可以使用Java将EBCDIC Comp-3文件转换为ASCII文件值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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