The Artima Developer Community
Sponsored Link

Java Answers Forum
search a large text file for a word

3 replies on 1 page. Most recent reply: Aug 26, 2003 2:34 AM by David

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
Brent

Posts: 1
Nickname: draziw123
Registered: Aug, 2003

search a large text file for a word Posted: Aug 16, 2003 1:17 PM
Reply to this message Reply
Advertisement
you know those cryptograms in the newspaper? Well i made a program that can solve them but it has to ask the user if the string it comes up with sould be the translation if you will. i know that the cryptograms will always be words and hopefully they will be common words. What i want to do is search a dictionary file (5 megs) for a word from the translation. if the word is in there is will assume that it has decoded the message and display it. ( i know it is a bad idea with alot of assuptions but bear with me :) ) so how do i search the file simply to see if one word is in the file without loading the file into a string or other sata structure (becasue of size)?


David

Posts: 150
Nickname: archangel
Registered: Jul, 2003

Re: search a large text file for a word Posted: Aug 18, 2003 12:48 AM
Reply to this message Reply
If you don't want to load the entire file into memory you only have one choice: load part of it into memory. It's up to you how much you want to load at a time (a line, 10 lines, 100 lines etc.).

Senthoorkumaran Punniamoorthy

Posts: 335
Nickname: senthoor
Registered: Mar, 2002

Re: search a large text file for a word Posted: Aug 23, 2003 5:20 PM
Reply to this message Reply
If your dictionary is categorized alphabetically I think it will be possible for you to create another small text file containing information on which line the words with that alphabet starts and where it ends

The text file might look something like this

A,1,121
B,122,200
...
...
...
Z,1001,1211

Something like that. The first number indicates where it starts and the second line indicates where the words Starting with A ends. So when you come across a word you can check against this file and load only that particular segment related to the first letter of the word.

This will solve your problem of how much to load in your memory and also make your search much faster since you are going to avoid on worst case searching 25 other segments which are guaranteed to not to have the word.

David

Posts: 150
Nickname: archangel
Registered: Jul, 2003

Re: search a large text file for a word Posted: Aug 26, 2003 2:34 AM
Reply to this message Reply
Nice solution - an index file! :-D

Flat View: This topic has 3 replies on 1 page
Topic: Array vs. ArrayList (or whatelse choice I have?) Previous Topic   Next Topic Topic: Priority Queue  linked list

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use