Reading Blank Lines into StringTokens into Vector Array

R

Row

HI,
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
entries)
------------------------------------------------------------------------------------------------------------------------------
12/2/2000
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();
urlConn.setDoInput(true);
urlConn.setUseCaches(false);

//------------------------------------------------//
// 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();
stringArray.addElement(line);


/*****
* ERROR!!!!!
* Attempt to output Vector below contents at element 0 - results on
all tokens
* being placed in first element of array (as seen below)
* !!!!!
*/
System.out.print(stringArray.elementAt(0));


/** 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();
//System.out.print(enum);
}

/** Whish to apend array contents to 2 different Textarea's on
different cards here **/
singleTextArea.setText(line);
fullTextArea.setText(line);

}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top