Hi, habe mal wieder ein Problem.
Hier mein kleines Java-Progrämmchen:
Ok, es ist wieder etwas lang. Aber ich denke, es ist trotzdem gut zu überblicken.
Habe Angst, daß wenn ich nur einen Ausschnitt zeige, ich wichtige Infos weglasse.
Das Programm greift auf die Klasse "Strings" zu, die u.a. folgendes enthält:
Das obige Programm erzeugt eine Binärdatei namens "AlleZeichen.dat".
Gucke ich nun hingegen in diese Datei mit einem Hexeditor, sieht sie wie folgt aus:
Das heißt, alle Zeichen von 0x80 bis 0x9F wurden durch ein 0x3F ersetzt !!!
Die restlichen Zeichen werden jedoch problemlos ausgegeben.
Hat irgendjemand dafür eine Lösung, wie ich jedes beliebige Byte in eine Datei schreiben kann?
Grüße
theuserbl
Hier mein kleines Java-Progrämmchen:
Java:
import java.io.*;
public class AlleZeichen {
public static void main(String[] args) throws IOException {
String Dat="";
String aload0=Strings.Chr(42);
String ret=Strings.Chr(177);
FileWriter datei = new FileWriter(new File("AlleZeichen.dat"));
Dat=Dat+ unhex("000102030405060708090A0B0C0D0E0F");
Dat=Dat+ unhex("101112131415161718191A1B1C1D1E1F");
Dat=Dat+ unhex("202122232425262728292A2B2C2D2E2F");
Dat=Dat+ unhex("303132333435363738393A3B3C3D3E3F");
Dat=Dat+ unhex("404142434445464748494A4B4C4D4EFF");
Dat=Dat+ unhex("505152535455565758595A5B5C5D5E5F");
Dat=Dat+ unhex("606162636465666768696A6B6C6D6E6F");
Dat=Dat+ unhex("707172737475767778797A7B7C7D7E7F");
Dat=Dat+ unhex("808182838485868788898A8B8C8D8E8F");
Dat=Dat+ unhex("909192939495969798999A9B9C9D9E9F");
Dat=Dat+ unhex("A0A1A2A3A4A5A6A7A8A9AAABACADAEAF");
Dat=Dat+ unhex("B0B1B2B3B4B5B6B7B8B9BABBBCBDBEBF");
Dat=Dat+ unhex("C0C1C2C3C4C5C6C7C8C9CACBCCCDCECF");
Dat=Dat+ unhex("D0D1D2D3D4D5D6D7D8D9DADBDCDDDEDF");
Dat=Dat+ unhex("E0E1E2E3E4E5E6E7E8E9EAEBECEDEEEF");
Dat=Dat+ unhex("F0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF");
datei.write(Dat);
datei.close();
System.out.println("Juhu!");
}
public static String unhex (String hexa) {
int abyte=0, bbyte=0;
String ahex, bhex;
String uhex="";
int i;
hexa=Strings.UCase(hexa);
for (i=1; i<=Strings.Len(hexa)/2; i++) {
ahex=Strings.Mid(hexa,i*2-1,1);
if (ahex.equals("0"))
abyte=0;
if (ahex.equals("1"))
abyte=1;
if (ahex.equals("2"))
abyte=2;
if (ahex.equals("3"))
abyte=3;
if (ahex.equals("4"))
abyte=4;
if (ahex.equals("5"))
abyte=5;
if (ahex.equals("6"))
abyte=6;
if (ahex.equals("7"))
abyte=7;
if (ahex.equals("8"))
abyte=8;
if (ahex.equals("9"))
abyte=9;
if (ahex.equals("A"))
abyte=10;
if (ahex.equals("B"))
abyte=11;
if (ahex.equals("C"))
abyte=12;
if (ahex.equals("D"))
abyte=13;
if (ahex.equals("E"))
abyte=14;
if (ahex.equals("F"))
abyte=15;
bhex=Strings.Mid(hexa,i*2,1);
if (bhex.equals("0"))
bbyte=0;
if (bhex.equals("1"))
bbyte=1;
if (bhex.equals("2"))
bbyte=2;
if (bhex.equals("3"))
bbyte=3;
if (bhex.equals("4"))
bbyte=4;
if (bhex.equals("5"))
bbyte=5;
if (bhex.equals("6"))
bbyte=6;
if (bhex.equals("7"))
bbyte=7;
if (bhex.equals("8"))
bbyte=8;
if (bhex.equals("9"))
bbyte=9;
if (bhex.equals("A"))
bbyte=10;
if (bhex.equals("B"))
bbyte=11;
if (bhex.equals("C"))
bbyte=12;
if (bhex.equals("D"))
bbyte=13;
if (bhex.equals("E"))
bbyte=14;
if (bhex.equals("F"))
bbyte=15;
uhex = uhex+Strings.Chr(abyte*16+bbyte);
}
return uhex;
}
}
Ok, es ist wieder etwas lang. Aber ich denke, es ist trotzdem gut zu überblicken.
Habe Angst, daß wenn ich nur einen Ausschnitt zeige, ich wichtige Infos weglasse.
Das Programm greift auf die Klasse "Strings" zu, die u.a. folgendes enthält:
Java:
public static String Chr(int Char) {
byte[] b = { (byte)Char };
try {
return (new String(b, "ISO-8859-1"));
} catch (Exception e) {
return (new String(b));
}
}
Das obige Programm erzeugt eine Binärdatei namens "AlleZeichen.dat".
Gucke ich nun hingegen in diese Datei mit einem Hexeditor, sieht sie wie folgt aus:
Code:
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F ................
10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F ................
20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F !"#$%&'()*+,-./
30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F 0123456789:;<=>?
40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E FF @ABCDEFGHIJKLMN.
50 51 52 53 54 55 56 57 58 59 5A 5B 5C 5D 5E 5F PQRSTUVWXYZ[\]^_
60 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F `abcdefghijklmno
70 71 72 73 74 75 76 77 78 79 7A 7B 7C 7D 7E 7F pqrstuvwxyz{|}~
3F 3F 3F 3F 3F 3F 3F 3F 3F 3F 3F 3F 3F 3F 3F 3F ????????????????
3F 3F 3F 3F 3F 3F 3F 3F 3F 3F 3F 3F 3F 3F 3F 3F ????????????????
A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 AA AB AC AD AE AF ................
B0 B1 B2 B3 B4 B5 B6 B7 B8 B9 BA BB BC BD BE BF ................
C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 CA CB CC CD CE CF ................
D0 D1 D2 D3 D4 D5 D6 D7 D8 D9 DA DB DC DD DE DF ................
E0 E1 E2 E3 E4 E5 E6 E7 E8 E9 EA EB EC ED EE EF ................
F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 FA FB FC FD FE FF ................
Das heißt, alle Zeichen von 0x80 bis 0x9F wurden durch ein 0x3F ersetzt !!!
Die restlichen Zeichen werden jedoch problemlos ausgegeben.
Hat irgendjemand dafür eine Lösung, wie ich jedes beliebige Byte in eine Datei schreiben kann?
Grüße
theuserbl