Read Uploaded file(data) into vector
2 posts in topic
Flat View  Flat View

Posted By:   Sharen_Su
Posted On:   Wednesday, June 19, 2002 01:45 AM

I can upload my file (txt file) to the server and able to read the data..Problem is the alignment of the text when it's read to a browser. The original alignment for the data in the txt file is nicely aligned. So is there any way to make the alignment same as the orignal txt file?? And also how can i pass the data into vectors? (my data is quite large)i mean how can i choose the column of data i wan to pass in to the vectors? (just like SQL statements) thanks..

Re: Read Uploaded file(data) into vector

Posted By:   Alex_Chaffee  
Posted On:   Friday, June 21, 2002 09:58 PM

(1) please don't ask more than one question at once

(2) use the < pre > tag, or use setContentType("text/plain");

(3) learn about the package for how to read a file -- sounds like you may need a StringTokenizer or StreamTokenizer to split your lines into fields.

Re: Read Uploaded file(data) into vector

Posted By:   John_Ewing  
Posted On:   Wednesday, June 19, 2002 06:42 AM

Browsers do not display the newline (
) character that is probably used to format your .txt file nicely. To make it look nice on the screen you will have to find the newline characters in your String and either replace them with
tags or add the
tags after the newline.

If you use spaces or tabs to format your data into columns, the browser will ignore these also. You should use the HTML tag to format your data into a table.

If you need to parse your data in to a data structure I would recommend a 2D Vector, or a Vector of Vectors. (Actually, unless you are using threads, I would use ArrayLists, Vectors unsynchronized cousin).

For the parsing start with StringTokenizer, if that doesn't do the job, move to a Regular Expression package, Apache has a nice one.

Good Luck!