473,387 Members | 1,844 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 4670
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Row | last post by:
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)...
2
by: adpsimpson | last post by:
Hi, I have a file which I wish to read from C++. The file, created by another programme, contains both text and numbers, all as ascii (it's a .txt file). A sample of the file is shown below: <<...
24
by: Hendrik Schober | last post by:
Hi, I have a 'std::istream' and need to read its whole contents into a string. How can I do this? TIA; Schobi
6
by: Dave Reid | last post by:
Hi everyone... I'm pretty much a newbie C++ user, and I've run into a problem. I'm trying to read in a large text file, and then do manipulations on it. I can read it into a large 2-dimensional...
5
by: JackM | last post by:
I need a little guidance putting a script together. I'm trying to read a list of image links from a text file (not a database) and display them in a table on my page. I want to display them in rows...
7
by: fakeprogress | last post by:
For a homework assignment in my Data Structures/C++ class, I have to create the interface and implementation for a class called Book, create objects within the class, and process transactions that...
3
by: bbepristis | last post by:
Hey all I have this code that reads from one text file writes to another unless im on a certian line then it writes the new data however it only seems to do about 40 lines then quits and I cant...
1
by: bbepristis | last post by:
Hey all I have a wired issue I have a csv file with , seperated values I have some code to read the file and put the record into an array then into textboxes. the problem is it seems to read...
3
by: lizii | last post by:
i have a file - which on each line has some data i need to fill into a box - now although reading in the data is simple enough and putting it in the correct box will be no problem, as i can just...
3
by: The Cool Giraffe | last post by:
Regarding the following code i have a problem. void read () { fstream file; ios::open_mode opMode = ios::in; file.open ("some.txt", opMode); char *ch = new char; vector <charv; while...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.