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 7793793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:35:56+00:00 2026-06-01T22:35:56+00:00

For example in C I have structure: typedef struct { int number; double x1;

  • 0

For example in C I have structure:

typedef struct {
    int number;
    double x1;
    double y1;
    double x2;
    double y2;
    double x3;
    double y3;
} CTRstruct;`

Then I write it to file fwrite(&tr, 1, sizeof(tr), fp); (tr – its CTRstruct var, fp – File pointer);

Then I need to read it with Java! I really don’t know how to read struct from file… I tried to read it with ObjectInputStream(), last idea is to read with RandomAccessFile() but I also don’t know how to… (readLong(), readDouble() also doesn’t work, it works ofcource but doesn’t read correct data). So, any idea how to read C struct from binary file with Java?


If it’s interesting, my version to read integer (but it’s ugly, & I don’t know what to do with double):

public class MyDataInputStream extends DataInputStream{

public MyDataInputStream(InputStream AIs) {
    super(AIs);
}

public int readInt1() throws IOException{
    int ch1 = in.read();
    int ch2 = in.read();
    int ch3 = in.read();
    int ch4 = in.read();
    if ((ch1 | ch2 | ch3 | ch4) < 0)
        throw new EOFException();
    return ((ch4 << 24) + (ch3 << 16) + (ch2 << 8) + (ch1 << 0));
}

with double we can deal the same way (like with int or with long (8bytes) & then convert to double with native func).

  • 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-01T22:35:58+00:00Added an answer on June 1, 2026 at 10:35 pm

    You have to find out what size those C types (int, double) and which endianness (thanks andrew cooke) are used in the architecture you executed the program in and use same sized types in Java.

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

Sidebar

Related Questions

For example, I have this structure and code: typedef struct { long long *number;
I have this complicated structure thingie: #include <stdlib.h> typedef struct { int x; int
For example I have a file name call A.java. Here its structure: public class
Coding in C: typedef struct { char *string; int one; int two; } Example;
Suppose I have a structure: typedef struct { float x; float y; float z;
I have the following for my HashTable structure: typedef char *HashKey; typedef int HashValue;
I have this structure: typedef struct { char *str; ... } nameType; I create
I have following structure with example data: id season_id title 1 1 Intro 2
I have the follow structure (example): trunk/ branches/v1.0.0 branches/v1.0.1 tags/v1.0.0 My question is: The
I have for example, a DB with the following entity and relation structure: [Person]

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.