Win a copy of Rust Web Development this week in the Other Languages forum!

Alice Peabody

Greenhorn
+ Follow
since Jul 17, 2001
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Alice Peabody

I am reading/writing/updating large data files and the RandomAccessFile() seems the best fit. The only problem is that using the primitive read member functions like readInt(), readFloat() etc takes too long.
It seems the read (byte[],int off, int len) function would help me with buffering my reads, but I'm still green under the collar when it comes to manipulating Java primitive types.
I'm used to c where I can use memcpy to copy from a buffer into an int, or a float. How do I read in a block of bytes and then save it as the appropriate types? What is the equiv in Java for:
char buffer[20];
int ival;
float fval;
char cval;
memcpy (&ival, buffer, 4);
memcpy (&fval, &buffer[4], 4);
memcpy (&cval, &buffer[8], 1);

Many thanks.
20 years ago