Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-19-2007, 07:57 PM
Member
 
Join Date: Nov 2007
Posts: 8
Warren is on a distinguished road
Vector create
how can i take every line of an input file and put in a Vector?
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-19-2007, 08:35 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,124
hardwired is on a distinguished road
Code:
import java.awt.*; import java.io.*; import java.util.*; import javax.swing.*; public class FileToVector { private JScrollPane getContent() { Vector<String> vector = new Vector<String>(); JTextArea textArea = new JTextArea(); File file = new File("FileToVector.java"); Scanner scanner = null; try { scanner = new Scanner(file); } catch(FileNotFoundException e) { System.out.println("file not found: " + e.getMessage()); } while(scanner.hasNextLine()) { String line = scanner.nextLine(); vector.addElement(line); } scanner.close(); for(int j = 0; j < vector.size(); j++) textArea.append(vector.get(j) + "\n"); return new JScrollPane(textArea); } public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(new FileToVector().getContent()); f.setSize(400,400); f.setLocation(200,200); f.setVisible(true); } }
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 11-19-2007, 08:51 PM
Member
 
Join Date: Nov 2007
Posts: 8
Warren is on a distinguished road
sorry I meant a .txt file not a .java. (by the way i dunno what JFrame, JTextArea, JScrollPane are, are they tools used a lot?)
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 11-19-2007, 09:13 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,124
hardwired is on a distinguished road
sorry I meant a .txt file not a .java.
Substitute a text file name in place of the java file. It should work okay.
(by the way i dunno what JFrame, JTextArea, JScrollPane are, are they tools used a lot?)
Yes.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Vector help king_arthur New To Java 3 01-22-2008 08:33 PM
Declaring Vector mew New To Java 1 12-05-2007 09:14 PM
Vector Capacity JavaForums Java Blogs 0 12-03-2007 01:10 AM
Array or Vector ravian New To Java 2 11-18-2007 07:19 PM
array vs Vector paty New To Java 1 08-02-2007 08:07 PM


All times are GMT +3. The time now is 09:17 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org