Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Vector input .txt

 
Oakley Bintang
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can I input a .txt file and put it in a Vector?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

First you'd have to define what you meant by that, exactly: probably you mean that each line of the file should be one element in the Vector, right? You could use java.io.BufferedReader class and its readLine() method in a loop. There's a program called "CopyLines" here which shows how to read the lines of a file.

Note that Vector is an old class and its use is discouraged; new code should use java.util.ArrayList as a replacement.
 
Oakley Bintang
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Each line of the txt file should be one element in the Vector. IF I use Arrays, then if i put a file that has a lot of elements i got problem right?
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Oakley Bintang:
IF I use Arrays, then if i put a file that has a lot of elements i got problem right?


Yes, but Ernest suggested you use an ArrayList not an array. An ArrayList is, in essence, a resizable array.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic