Search code examples
javatext-filesjtextfieldbufferedreaderstringtokenizer

Reading small parts of a text file into a text field in GUI


Im going to write a hotel reservation program for my final year at school. I am going to use a text file to have all the guests whose attributes include: Name, Surname, contact details etc. and I want to read these attributes back to the text fields they were entered in to but they will be the same fields and labels and everything but in a different page. I will be using a StringTokenizer when writing to the file so there will be e.g. a '#' separating each attribute.

Can someone please help with reading each attribute separately into separate text fields so e.g. the text file will look something like this:

Sam#Haden#[email protected]#7562234#

and I want each attribute to be read to a separate text field.


Solution

  • You could use String.indexOf("#") to find a hash tag, then use that index to create a substring with just the first element, and a substring of the remaining elements. Then repeat the process until everything is split into the separate text fields.