Solved

reading bytes from a file into an array

Posted on 2003-11-29
5
291 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

776 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