Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Help with reading from file

  1. #1
    Junior Member
    Join Date
    Jun 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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


  2. #2
    Member
    Join Date
    May 2010
    Posts
    38
    Thanks
    1
    Thanked 8 Times in 7 Posts

    Default 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.

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Help with reading from file

    could split by \n\r to split by new lines
    A BufferedReader.readLine() method could take care of that part.

  4. #4
    Junior Member
    Join Date
    Jun 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.

Similar Threads

  1. Reading file
    By nasi in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 3rd, 2010, 03:14 AM
  2. Anyone Help me in XML file Reading??????????
    By goplrao in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: May 2nd, 2010, 11:04 AM
  3. [SOLVED] reading only certain lines from a .txt file
    By straw in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: March 7th, 2010, 07:49 PM
  4. [SOLVED] File Reading from the specified location
    By rajesh.mv in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: August 13th, 2009, 12:56 AM
  5. [SOLVED] Problem in reading a file from java class
    By aznprdgy in forum File I/O & Other I/O Streams
    Replies: 11
    Last Post: March 23rd, 2009, 09:31 AM