io - is Scanner in Java enough for reading input from a text file? -
what i'm going do
i'm going build phone book program in java following jobs:
- read 2 text files, instruction.txt , phonebook.txt
- phonebook.txt includes phone entry, each entry person
- instruction.txt includes instructions execute phonebook.txt, such add new entry, query entry, delete entry, etc.
- for sure care output of program, now, focus on input.
my problem
i want use scanner input jobs, read in strings stored in instruction.txt , phonebook.txt, doubt if can handle difficult conditions. conditions how correctly each entry, , identify is.
for each phone book entry, 5 fields needed: name, birthday, phone number, address, email. , name , birthday compulsory each entry.
for instructions, add, delete, save, read, query.
sample text files
here sample of instruction.txt:
add name testing three; birthday 13-05-1982; phone 12345677; address address three; email testing@gmail.com delete testing 1 save
each entry separated 1 or more blank lines. here sample of phonebook.txt:
name testing one
birthday 13-05-1980
phone 12345678
address address one
email testing1@gmail.com
-----------this blank line -------------------------
name testing two
birthday 13-05-1981
phone 12345644
address address two
email testing2@gmail.com
yes, scanner sufficient reading, though you'd need use right way.
getting entries matter of calling scanner.next...
method, , can deal optional fields using hasnext...
.
(hint: use 1 scanner split lines, , new scanner split each line.)
Comments
Post a Comment