Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Vector of byte arrays - how to get my data out?

 
Ichiro Takeshita
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

This is my first post here at Java Ranch. I'm wondering if someone can educate me.

I have a vector (fileDataList). Within a loop I am adding arrays of bytes (the return value from readFile(filename)) thus:




As you can see from the second line of the example above I am comfortable with casting object back to their original type when reading them from a vector.

But how do I get my byte arrays back out of the fileDataList? What cast can I use? The code below won't work because we can't convert from Object to byte[]



Is there a simple answer?

I.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

"data = (byte[]) fileDataList.elementAt(i)" would work just fine.
 
Ichiro Takeshita
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ernest,

Thanks for such a fast reply.

As an experienced programmer, yet Java beginner I often find myself able to write some amazing code in no time at all, only to be stumped for eternity on a simple problem such as this.

Thanks for saving me from further frustration.

I.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic