Transformer EBCDIC en ASCII en JAVA - Java - Programmation
Marsh Posté le 02-12-2007 à 13:46:57
Est tu certain de la validité de ton tableau "tabASCII_EBCDIC" car j'utilise le même principe (tableau de conversion) pour convertir des fichier et cela ne me pose aucun problème (sauf bien sur les valeurs numériques paqués).
Marsh Posté le 24-11-2007 à 20:38:55
Bonjour,
. Voici mon code :
j'ai fait un programme permettant de lire dans un fichier le code en EBCDIC et retourne un fichier en ASCII, mais cela ne marche que pour un certain nombre de caractères
public static void main(String[] args) throws Exception {
int[] tabASCII_EBCDIC = new int[999999];
String encoding = "Cp1147";
char car;
byte[] b2 = new byte[256];
for (int i = 0; i < 256; i++) {
b2[i] = (byte) i;
}
String x = new String(b2, encoding);
for (int i = 0; i < x.length(); i++) {
if ((x.charAt(i) != i)) {
car = (char) i;
tabASCII_EBCDIC[(int) i] = (int) x.charAt(i);
}
}
String chemin = "C:\\Documents and Settings\\FileEBCDIC.txt";
File fileEBCDIC = new File(chemin);
long TailleFileEBCDIC = fileEBCDIC.length();
int bloc = 1;
// Fichier sortie en ASCII
FileWriter fwASCII = new FileWriter("C:\\Documents and Settings\\FileASCII.txt" );
BufferedWriter bwASCII = new BufferedWriter(fwASCII);
PrintWriter fichierSortie = new PrintWriter(bwASCII);
while (bloc <= TailleFileEBCDIC) {
System.out.println("Passage N° :" + bloc);
byte[] b = new byte[bloc];
InputStream inputSIndexV2 = new FileInputStream(chemin);
inputSIndexV2.read(b);
String machaine = new String(b);
char caractereEntree = machaine.charAt(bloc - 1);
int CodeASCIICaractere = (int) caractereEntree;
int codeEBCDICCaractere = tabASCII_EBCDIC[CodeASCIICaractere];
char CaractereASCIIARetourner = (char) codeEBCDICCaractere;
fichierSortie.print(CaractereASCIIARetourner);
bloc = bloc + 1;
}
fichierSortie.close();
}
si dans le fichier FileEBCDIC.txt je met ces caracteres en EBCDIC ‚�•˜¤…
en résultat je devrait avoir le mot banque
avec mon programme il y a que le caractere 'u' sort bien
Est ce que quelqu'un pourrait m'aider, en gros le résultat attendu est d'avoir un truc comme celui de ce site :
http://www.iconv.com/asciiebcdic.htm
Merci beaucoup