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.


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

Results 1 to 2 of 2

Thread: Fastest way to read and search a string in a large file using java

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Thanked 0 Times in 0 Posts

    Default Fastest way to read and search a string in a large file using java

    Hi All,

    I want to read a file and search string in file and returns it's related value.

    The file contains key and value pair and they are separated by space. Key is string and value is and URL in <a> tag, and the file size is 60MB.

    I read the file using file Input stream and stored it into hash Map and performed searching into hash map, and it's taking less than a second to read the file and search a string and return it's value.

    The searching in file having some rules as:
    1. search string in file can be a sentence, we have to search the matching key into the file and return all the values(URL). and the search string length should be greater than 10.
    2. if the search string contains _(underscore) at the end, then if the exact match(key) found in the file then no need to check the length of search string.

    e.g. of Search Sting :
    This is my first post to Java Programming Forums.

    If the file contains Programming key, then we should have to return all URL related to this key.

    I tried using file scanner, buffer Reader, File Input Stream and direct search in file and using hash map. But using hash map the performance was better.

    Can please anybody suggest me how can I improve the performs so that I can achieve the file read and search within 5 Milliseconds. This will be an great help for me..

    Thanks a lot in advance....

  2. #2
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    My Mood
    Thanked 140 Times in 135 Posts

    Default Re: Fastest way to read and search a string in a large file using java

    Please re-read the forum FAQ, and abide by the forum rules including not double posting your question. Please choose which forum would be best for your question and close or delete the other one. I'll remove this comment once you've done that.

Similar Threads

  1. HW-how to read a string from a text file
    By yaboibangz in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 1st, 2012, 09:34 AM
  2. Inserting Large XML file into Oracle Database through java
    By hari_582 in forum JDBC & Databases
    Replies: 0
    Last Post: April 14th, 2012, 03:19 PM
  3. search string in a text file
    By dewet in forum Android Development
    Replies: 2
    Last Post: April 10th, 2012, 02:39 PM
  4. java.net.HttpURLConnection:large file to upload
    By tommy_725 in forum Java Networking
    Replies: 1
    Last Post: October 28th, 2009, 11:53 AM
  5. exception while Read very large file > 300 MB
    By ps.ganesh in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: June 11th, 2009, 11:39 PM