java - Binary file reader byte[] to string conversion gone wrong? -


i'm trying display whats in file header should text (the rest of file binary) when print strtemp this:

strtemp: ?????? 

here code.

string filename = "test.file";  uri loguri = new file(filename).getabsolutefile().touri();    bufferedinputstream in = new bufferedinputstream(new fileinputstream(new file(loguri)));   byte[] btemp = new byte[14]; in.read(btemp);  string strtemp = "";  for(int = 0; < btemp.length; i+= 2) {     strtemp += string.valueof((char)(((btemp[i]&0x00ff)<<8) + (btemp[i+1]&0x00ff))); }  system.out.println("strtemp: " + strtemp); 

how strtemp whats in file? , display properly?

as can see constructor summary of http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/string.html can initialize string bytes directly.

also should supply charset have in source file.


Comments

Popular posts from this blog

How do you change vbulletin's home page to the forums instead of the default (CMS or Activity Stream)? -

c++ - Troubles when compiling phash program -