Solved

reading bytes from a file into an array

Posted on 2003-11-29
5
287 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
Comment Utility
code looks alright, can you post the code that is using the loaded array?
0
 

Author Comment

by:abstractionz
Comment Utility
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
Comment Utility
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
Comment Utility
You need to use RandomAccessFile.
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
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 …

743 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now