• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

reading into a vector

 
Chanpreet Julka
Ranch Hand
Posts: 40
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am reading from a BufferedInputStream, which has data from a database. I wan't insert the data into a vector as strings, but It doesn't work like this, because it inserts the byte and I get an error. Please help.
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec("some directory");
InputStream stream = proc.getInputStream();
BufferedInputStream in = new BufferedInputStream(stream);
int i = 0;

while( (i = in.read()) != -1) {
v.addElement(i);
System.out.write(i);
}
 
Dale DeMott
Ranch Hand
Posts: 515
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you'll need to identify how you want these bytes put together before you put them into a vector. Do you want to put them in as words, sentences or other. You can't bytes into the Vector because vectors only accept objects. A byte is a primative and won't go into it. I guess the question then is, what is your purpose of doing this. Then you can decide how to put these bytes together. Once you have this... maybe in some String format.... then you can easily put them into a Vector.
-Dale
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic