I tried to read a file using Java.This file do not have a file type. When I use UltraEdit text editor to open it,it looks like this: The first line in file is
00 00 10 01 00 51 21 E4 22 0D 6D F1 81 51 21 E2.
I also checked the File encoding format in UltraEdit, it's ANSI.But how to read this file in 00 00 10....this way and print data on the Console?
I have eclipse in Java 1.7.I tried to read that file in "GBK","GB2312","UTF-8",but did not work.When I tried to read it in "ANSI",then this is a error,
Error message
Exception in thread "main" java.io.UnsupportedEncodingException: ANSI.
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
public class Deconde{
public static void main (String []args) throws Exception{
//File byte stream
FileInputStream fis=new FileInputStream("D:\\0testData\\Data_21");
//A bridge of byte streams and character streams that can specify a specified character format
InputStreamReader isr=new InputStreamReader(fis,"ANSI");
String str=null;
int c=0;
while((c=isr.read())!=-1)
System.out.print((char)c);
System.out.println("_______________________________________________");
//Read characters directly, as long as the encoding problem is ok
BufferedReader br=new BufferedReader(isr);
str=br.readLine();
while(str!=null)
{
System.out.println(str);
str=br.readLine();
}
System.out.println("______________________________________________________");
//Use the default encoding of the InputStreamReader, no problem when it is ANSI
BufferedReader br2=new BufferedReader(new InputStreamReader(fis));
str=br2.readLine();
while(str!=null)
{
System.out.println(str);
str=br2.readLine();
}
}
}
```