Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

reading bytes from a file into an array

Posted on 2003-11-29
5
292 Views
Last Modified: 2012-05-04
i am trying to read sets of bytes from a file into a 2d array.  my loop looks like this:

for ( int i = 0; i < numOfSets; i++) {
  theSets[i][0] = read in part of Set1;
  theSets[i][1] = read in part of Set1;
                     .
                     .
}

however, once the loop is finished, i only have the last set of bytes and its parts filling the whole array.
0
Comment
Question by:abstractionz
  • 3
  • 2
5 Comments
 
LVL 92

Expert Comment

by:objects
ID: 9844344
code looks alright, can you post the code that is using the loaded array?
0
 

Author Comment

by:abstractionz
ID: 9844408
after posting the question i figured out what the problem was.  by accident i assigned the array objects to the same array.
0
 

Author Comment

by:abstractionz
ID: 9844435
perhaps you can help me with another question.  how do i write to a file a certain number of bytes into it.  i know DataInputStream has skipbytes but i don't see anything like that for DataOutputStream.
0
 
LVL 92

Accepted Solution

by:
objects earned 125 total points
ID: 9844452
You need to use RandomAccessFile.
0
 
LVL 92

Expert Comment

by:objects
ID: 9844472
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This video teaches viewers about errors in exception handling.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question