469,638 Members | 1,560 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,638 developers. It's quick & easy.

Reading Blank Lines into StringTokens into Vector Array

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);

}
}
Jul 17 '05 #1
1 4448
Row
Sorry about the double post guys i didn't realise that had happend.
Is there anyone out there who can answer this for me?
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by adpsimpson | last post: by
24 posts views Thread by Hendrik Schober | last post: by
6 posts views Thread by Dave Reid | last post: by
7 posts views Thread by fakeprogress | last post: by
3 posts views Thread by bbepristis | last post: by
1 post views Thread by bbepristis | last post: by
3 posts views Thread by lizii | last post: by
3 posts views Thread by The Cool Giraffe | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.