Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8404159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:31:41+00:00 2026-06-09T22:31:41+00:00

I have to read data from a binary file like S/W version,vendor etc. i

  • 0

I have to read data from a binary file like S/W version,vendor etc.
i have to show the output in a textarea.After reading the configurations the usre can send the selected file through a serial port.
I have written some code here:

InputStream is=null;
    try {
        File urt=filebrowser.getSelectedFile();
        is = new FileInputStream(urt);
        DataInputStream in = new DataInputStream(is);
        long l=urt.length();

        char[] bytes= new char[(int)l];
         int o=bytes.length;
         errlabel.setText(String.valueOf(o));
         String content;
        int offset;
   BufferedReader br = new BufferedReader(new InputStreamReader(in));
         int numRead;
        try {

         br.read(bytes, 0, 46);
         while ((content = br.readLine()) != null)   {
StringBuilder sb=new StringBuilder(content);

jTextArea1.setText(sb.toString());
errlabel.setText(""+sb.length());


}





        } catch (IOException ex) {
            Logger.getLogger(MyBoxUpdator.class.getName()).log(Level.SEVERE, null, ex);
        }


    } catch (FileNotFoundException ex) {
        Logger.getLogger(MyBoxUpdator.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        try {
            is.close();
        } catch (IOException ex) {
            Logger.getLogger(MyBoxUpdator.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

And The Output

EE��6**UT�h��}�(:�萢Ê�*:�茢���_��(RQ��N���S��h����rMQ��(_Q����9mTT��\�nE�PtP�!E�UtBߌz��z���������

What may be wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T22:31:43+00:00Added an answer on June 9, 2026 at 10:31 pm

    You are converting bytes into chars

    So you must tell what encoding to use. If you don’t indicate one the InputStreamReader (it is: reader that reads chars from an input stream of bytes) will use a default. I’m sure the default is not what you need.

    Try this:

    new InputStreamReader(in, "UTF-8"); // or whatever encoding you need
    

    As a general rule: always indicate encoding when dealing with char to bytes conversion and viceversa! 🙂

    Edit

    Of course, I’m assuming your file has TEXT encoded into it. If it’s binary as @alfasin said… well… it’s normal to see garbage. You should read bytes and write chars representing them (as an hex representation of each byte, by example).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to display image data read in from a binary file (I have
Hi everyone i have an issue while reading binary data from a binary file
I have Uitable with data read from a AScii file. I want to select
I need to read a large (2000x2000) matrix of binary data from a file
i'd like to read binary data from a blob, using the Stream interface around
I have binary data in a file that I can read into a byte
I'm trying to read data in from a binary file and then store in
I have made a code that read data from flash Nand (without filesystem). fd
I have a static initialization block where I read data from DB into certain
I am trying to read data from an RS-232 port. Does anyone have an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.