File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Vector input .txt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Vector input .txt" Watch "Vector input .txt" New topic
Author

Vector input .txt

Oakley Bintang
Greenhorn

Joined: Nov 19, 2007
Posts: 2
How can I input a .txt file and put it in a Vector?
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

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.


[Jess in Action][AskingGoodQuestions]
Oakley Bintang
Greenhorn

Joined: Nov 19, 2007
Posts: 2
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

Joined: Aug 05, 2005
Posts: 3426
    
  12
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.


Joanne
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Vector input .txt
 
Similar Threads
Vectors within vectors
Vectors within vectors
a file problem - pretty urgent
Still can't write vector to file...?
<identifier> expected problem - Vectors.