Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Reading Blank Lines into StringTokens into Vector Array

Thread Tools

Reading Blank Lines into StringTokens into Vector Array

Posts: n/a
I would first like to say its been about 3 years since looking at java
im very rusty!
I have to write a post it notes type applet which will function
online. (reading from a flat text file)
My main problem is: getting each paragraph into my vector array - so
that each paragraph sits in a new array element. Eg: when i referance
array elemant 2 it will give me paragraph which is in that element and
not all paragraphs in the text file like my program is doing now

Read from my text file which will look like this: (but with more
Post it note contents get put here and can span several lines
depending on how they are input.
Linke this

3 blank lines - then the next entry....
I hope i make sense!. As i said before i am really rusty on this...i
sold my old java books so i am now spedning days on end trying to sort
anything out.

My code is below:

/** Define the Method - which reads values from server and places them
into textAreas **/
void getList() {

try {

/** Define connection parameters **/
URL url;
URLConnection urlConn;
DataInputStream dis;
urlTx = urlText.getText();

/** URL comes from text field **/
url = new URL(urlTx);
urlConn = url.openConnection();

// read the To-Do List data from the HTTP server //

/** Define Data input stream after defining URL etc above **/
dis = new DataInputStream(urlConn.getInputStream());
String s;

/** While not null take following actions **/
while ((s = dis.readLine()) != null) {
String data = new String(s + "\n");
String line;

/** Tokenize the string which as been input and read this string into
an array**/
StringTokenizer strtokLines = new StringTokenizer(data, "\n");

/** vector to store String tokens in **/
stringArray = new Vector();

/** While has more tokens define "line" as next token and add "line"
to Vector */
while (strtokLines.hasMoreTokens()) {
line = strtokLines.nextToken();

* ERROR!!!!!
* Attempt to output Vector below contents at element 0 - results on
all tokens
* being placed in first element of array (as seen below)
* !!!!!

/** Test if Array actually has contents if not state so **/
if ((stringArray.isEmpty() == true)) {
System.out.println("Vector array is EMPTY!!");
} else {
//enumeration = vector contents
Enumeration enum = stringArray.elements();

/** Whish to apend array contents to 2 different Textarea's on
different cards here **/

Reply With Quote

Thread Tools

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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading lines from a file into an array Jim Burgess Ruby 2 05-01-2010 01:32 PM
Initializing vector<vector<int> > and other vector questions... pmatos C++ 6 04-26-2007 05:39 PM
Preserve blank lines when add multiple lines of text to a cell Cah Sableng Javascript 0 04-23-2007 04:46 AM
Free memory allocate by a STL vector, vector of vector, map of vector C++ 8 02-18-2006 12:48 AM
Uniform vector class, inheriting from Array: How to make sure thatmethods return a Vector and not an Array? Thomas Ruby 7 05-23-2005 04:21 PM