By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,962 Members | 1,776 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,962 IT Pros & Developers. It's quick & easy.

Reading Blank Lines into StringTokens into Vector Array

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.