Java - Conversor bytes to hexadecimal

 
Vista:
sin imagen de perfil
Val: 87
Ha aumentado su posición en 2 puestos en Java (en relación al último mes)
Gráfica de Java

Conversor bytes to hexadecimal

Publicado por Tomas (76 intervenciones) el 25/10/2015 20:09:22
Hola, hice un programa que lee bytes de un fichero y los imprime en hexadecimal, pero solo imprime las vocales(debería imprimir "hola", solo imprime "oa" ;no veo el fallo ni tengo claro cuando estoy usando UTF-8/16, ASCII, ANSI o UNICODE. ¿Alguien me puede explicar?
Gracias.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import java.io.*;
import java.util.Scanner;
 
public final class HexViewer {
	public final static void printFile(String filePath) throws IOException {
 
		Scanner input = new Scanner(System.in);
 
		String ruta;
		System.out.println("Escribe la ruta del fichero: ");
		ruta = input.nextLine();
		FileInputStream fitxerEntrada = new FileInputStream(ruta);
			while (fitxerEntrada.read() != -1) {
 
					for (int i=0; i <= 8; i++) {
						int readByte = fitxerEntrada.read();
 
						System.out.print(Integer.toHexString(readByte));
					}
				}
			fitxerEntrada.close();
			input.close();
	}
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder