Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Hex Code Generation Problem

807603Feb 6 2008 — edited Feb 9 2008
Hello

I want the hex code of files for which I am using the following functions
public static String displayBinaryFile2(File f) throws IOException 
{
String hex=""; 
String hex2="";
BufferedInputStream in = new BufferedInputStream(new FileInputStream(f));
int b,i=0,c=0;
int count=0;
while ((b = in.read()) != -1) { c++;
try { 
hex=Integer.toHexString(b);
hex2=hex2+hex; 
} catch(Exception e){System.out.println("Example5.java"+e);}
//System.out.println("HEX2:"+hex2);
if (hex.length() == 1)
hex = '0' + hex;
} //end of func
in.close();
return hex2;
This code works fine for small files. But for large files, the console through which I run my GUI becomes unresponsive.
Can anyone suggest a better hexadecimal conversion method ?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 8 2008
Added on Feb 6 2008
15 comments
365 views