简体   繁体   English

Java程序的示例EBCDIC文件,用于将EBCDIC转换为ASCII

[英]example EBCDIC file for Java program to convert EBCDIC to ASCII

I am trying to convert EBCDIC file to ASCII using following code : 我正在尝试使用以下代码将EBCDIC文件转换为ASCII:

InputStreamReader rdr = new InputStreamReader(new FileInputStream(<your file>),java.nio.Charset.forName("ibm500"));    
    while((String line = rdr.readLine()) != null) {
        System.out.println(line);

I am trying to find a sample file in EBCDIC format to send it as an input to this program. 我正在尝试查找EBCDIC格式的样本文件,以将其作为输入发送到该程序。 Can anyone please point me to a sample file. 谁能给我指出一个示例文件。 can't find anything online. 在网上找不到任何东西。

You can use the iconv utility on Unix to convert between character encodings. 您可以在Unix上使用iconv实用程序在字符编码之间进行转换。 It is also available for Windows (it's an optional package you can install in Cygwin, for example). Windows也可以使用它(例如,这是一个可选软件包,可以在Cygwin中安装)。 You can also use the dd command to convert character encodings. 您还可以使用dd命令转换字符编码。

dd if=ascii.txt of=ebcdic.txt conv=ebcdic

You should also be able to use Java to do the conversion in the other direction from the way you're currently doing it. 您还应该能够使用Java在与当前操作相反的方向上进行转换。 Just read the file as ASCII and write it as EBCDIC. 只需将文件读取为ASCII并将其写入EBCDIC。

Here is an array with the 255 EBCDIC characters: 这是一个包含255个EBCDIC字符的数组:

var ebcdic = [
'NUL', // Null
'SOH', // Start of Heading
'STX', // Start of Text
'ETX', // End of Text
'PF',  // Punch Off
'\t',  // Horizontal Tab
'LC',  // Lower Case
'DEL', // Delete
' ', ' ',
'SMM', // Start of Manual Message
'\v',  // Vertical Tab
'\f',  // Form Feed
'CR',  // Carriage Return
'SO',  // Shift Out
'SI',  // Shift In
'DLE', // Data Link Escape
'DC1', // Device Control 1
'DC2', // Device Control 2
'TM',  // Tape Mark
'RES', // Restore
'\n',  // New Line
'\h',  // Backspace
'IL',  // Idle
'CAN', // Cancel
'EM',  // End of Medium
'CC',  // Cursor Control
'CU1', // Customer Use 1
'IFS', // Interchange File Separator
'IGS', // Interchange Group Separator
'IRS', // Interchange Record Separator
'IUS', // Interchange Unit Separator
'DS',  // Digit Select
'SOS', // Start of Significance
'FS',  // Field Separator
' ',
'BYP', // Bypass
'\n',  // Line Feed
'ETB', // End of Transmission Block
'ESC', // Escape
' ', ' ',
'SM',  // Set Mode
'CU2', // Customer Use 2
' ',
'ENQ', // Enquiry
'ACK', // Acknowledge
'BEL', // Bell
' ', ' ',
'SYN', // Synchronous Idle
' ',
'PN',  // Punch On
'RS',  // Reader Stop
'UC',  // Upper Case
'EOT', // End of Transmission
' ', ' ', ' ',
'CU3', // Customer Use 3
'DC4', // Device Control 4
'NAK', // Negative Acknowledge
' ',
'SUB', // Substitute
' ', // Space
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
'¢', '.', '<', '(', '+', '|', '&', 
    ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
'!', '$', '*', ')', ';', '¬', '-', '/', 
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
',', '%', '_', '>', '?', 
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
':', '#', '@', '\'','=', '\"',' ',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 
' ', ' ', ' ', ' ', ' ', ' ', ' ', 
'j',  'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 
's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', 
'`', // Grave Accent
' ', ' ', ' ', ' ', ' ', ' ', ' ',
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 
' ', ' ', ' ', ' ', ' ', ' ', ' ', 
'J',  'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 
'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
' ', ' ', ' ', ' ', ' ', ' ', 
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 
' ', ' ', ' ', ' ', ' ', ' '
]

You can then convert a buffer with EBCDIC encoded text like this: 然后,您可以使用EBCDIC编码的文本转换缓冲区,如下所示:

var result = ''
for (var i = 0; i < buffer.length; i++) {
    result += ebcdic[buffer[i]]
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM