Help with reading from file
Hi, I am trying to write some applications about movie ticket reservation. It's a client server based, I i done that also like logging users and showing which movies are available.
Now I need to do a ticket reservation. All reservation I am keeping in reservation.txt. If anyone can help me how to wite a method to read just how many tickets are free for that movie,
i.e Dark Knight*10. I want to read just this "10" and to manipulate with that. If user reservates three tickets to write here "7".
And how to read or write just let's say third line
Dark Knight*10
Superman*11
Avatar*14
Batman*12.
Thank's
Re: Help with reading from file
For simplicity your going to have to parse the whole file into a map, modify the map, then write it to a clean version of the file. Its either that or regex.
You could split by \n\r to split by new lines, then split by *, and store the results in a map.
Re: Help with reading from file
Quote:
could split by \n\r to split by new lines
A BufferedReader.readLine() method could take care of that part.
Re: Help with reading from file
You can also tokenize the content of the file based on the * character and put every time the contents into a string array of two positions and use the second one.