• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Vector input .txt

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How can I input a .txt file and put it in a Vector?
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic