Hallo,
ich will eine XML-Datei byteweise einlesen und dann entweder schauen was im encoding="" Attribut steht oder falls nicht angegeben ob das Zeichen "<" möglicherweise als UTF-16 Big- oder Little Endian kodiert wurde, ansonsten nehme ich UTF-8 an.
Ich wollte zuerst in einen StringBuffer einlesen, aber das verändert mir wohl schon die Kodierung. Ansonsten wenn ich einfach in eine Variable vom Typ byte einlese, dann bekomme ich komischerweise eine Nullpointer Exception, jedes zweite Byte ist 0 (angefangen an beim ersten, also das 1., 3. usw.) wohl wegen UTF-16 Big Endian, aber das dürfte doch keine NullPointer Exception auslösen?
oder
Ich will dann auch die Hexadezimal-Werte vergleichen können, also irgendwie
Viele Grüße,
Johannes
ich will eine XML-Datei byteweise einlesen und dann entweder schauen was im encoding="" Attribut steht oder falls nicht angegeben ob das Zeichen "<" möglicherweise als UTF-16 Big- oder Little Endian kodiert wurde, ansonsten nehme ich UTF-8 an.
Ich wollte zuerst in einen StringBuffer einlesen, aber das verändert mir wohl schon die Kodierung. Ansonsten wenn ich einfach in eine Variable vom Typ byte einlese, dann bekomme ich komischerweise eine Nullpointer Exception, jedes zweite Byte ist 0 (angefangen an beim ersten, also das 1., 3. usw.) wohl wegen UTF-16 Big Endian, aber das dürfte doch keine NullPointer Exception auslösen?
Code:
FileInputStream in = new FileInputStream(args[0]);
StringBuffer buf = new StringBuffer();
int ch;
for(int i = 0; (ch = in.read()) != -1; i++) {
out.println(Integer.toHexString(ch));
/*
* Read the first characters until e, the first letter of
* encoding must have been read -- if it's not read skip the
* reading of the file.
*/
if (i == 20 && Integer.toString(ch) != "e") {
break;
} else {
buf.append(ch);
}
}
in.close();
oder
Code:
FileInputStream in = new FileInputStream(args[0]);
byte[] buf
int ch;
for(int i = 0; (ch = in.read()) != -1; i++) {
out.println(Integer.toHexString(ch));
/*
* Read the first characters until e, the first letter of
* encoding must have been read -- if it's not read skip the
* reading of the file.
*/
if (i == 20 && Integer.toString(ch) != "e") {
break;
} else {
buf[0] = (byte) ch;
}
}
in.close();
Ich will dann auch die Hexadezimal-Werte vergleichen können, also irgendwie
Code:
if (buf[0] == (byte) 0x00 && buf[1] == (byte) 0x3C)
Viele Grüße,
Johannes