Binary search in a text file.

Is it possible to carry out binary search directly in the text file without passing the file data into a List data, in order to save RAM?

If the file is sorted, and if you know what byte position each record begins at, then, yes, using RandomAccessFile you can do this.
I don't know if it's really the best approach though. If the file's not all that big, or if the relevant parts of its content can be represented in more compact form, then sorting in memory will be simpler and quicker.

Similar Messages

  • [svn:osmf:] 11361: Adding a generic binary search utility ( updating project file).

    Revision: 11361
    Author:   [email protected]
    Date:     2009-11-02 05:21:35 -0800 (Mon, 02 Nov 2009)
    Log Message:
    Adding a generic binary search utility (updating project file).
    Modified Paths:

    try this forum: WebCenter Portal

  • Write diadem search results to text file

    Is there a solution within DIAdem for exporting specific information from a search result into a text file? For example: I perform a search which returns all of the files, groups, and/or channels which I want to work with; now I would like to have, say, the file paths of all the results of my search exported to a text file. Is this possible? I could not find a direct way of doing this, but perhaps a script already exists for doing stuff like this?

    Hi mrclary,
    I did not have this code handy, but I was able to whip it up for you.  Let me know if you have any questions.
    Brad Turpin
    DIAdem Product Support Engineer
    National Instruments
    Search Result ‏1 KB

  • Search word in text file

    someone can help me with code?
    How to search in text file any word and count how many it were repeated?
    For example test.txt:
    hiAnd if I want to know how many times are repeated in test.txt word "Hi" program must say "3 times repeated"
    I hope you understood what I want, thank you for answers.

    This is my code now.
    package lt.kvk.i3_2.test;
    import java.util.Scanner;
    public class Testing {
              public static void main(String args[]) throws Exception {
                   Scanner input = new Scanner(;
                System.out.println("Select word from list:");
                try {
                        FileReader fr = new FileReader("src/lt/kvk/i3_2/test/List.txt"); // this is list of words, everything all right here
                        BufferedReader br = new BufferedReader(fr);
                        String s;
                        while((s = br.readLine()) != null) {
                        String stilius = input.nextLine();   // eneter word which I want to count in File.txt
                    BufferedReader bf = new BufferedReader(new FileReader("src/lt/kvk/i3_2/test/File.txt")); // from this file I need to count word which I entered before
                    int counter = 0;               
                    counter = counter + 1;
                    counter += 1;
                    String line;
                    System.out.println("Looking for information");
                    while (( line = bf.readLine()) != null){
                    int indexfound = line.indexOf(stilius);
                    if (indexfound > -1) {
                    System.out.println( "At all words which You want to count are "+ counter);
                catch (IOException e) {
              }         Here example of file.txt:
    testIf I enter for example word "test" or any from this list I got answer:
    Looking for information
    At all words which You want to count are 3But it must to count how many times in this file this word are repeated, it must be 4
    if I enter word car It must show 2....
    And if I enter word which isn't in list (file.txt)
    Program didn't show error, just:
    Looking for informationThanks for answers.

  • Searching for a text file

    hi i want to search for a file in the same folder as my project and read the contents of that file ... i know how to read from text file but i just need to know how i can search in the folder to look for a txt file called me.txt and open it for reading.. any suggestions?
    thanks in advance
    please provide some code for me... thx alot

    Look at the File class in Java API. You can create a file object by passing the file name.
    Then you can check whether the file exists or not by using exist methos of the File. (Of course, you need to know the path of the file).

  • Need to search contents of text files on a windows network drive....

    I am trying to search the content of a directory on a windows network drive for that contains .sas files (essentially text files) for a certain text string. Find does not seem to do this. Any ideas/suggestions?
    When I copy a file to my desktop I can do it easily, but that is not an option.

    Uh my opinion GREATLY affects Apple's claim to windows compatibility......unless there is a solution out there. My firm is windows-based and we have a terabyte or so of data and files related to various stuff all buried in subfolders..and all I want is to search one folder for one text string.
    I'm praying for a solution here.....

  • Binary search in text files

    Hi all,
    I'm thinking about how to implement a binary sort to get,given a key, a value from a text file with a list of words in order. I saw randomaccessfile for j2se and I know that this work it's usually done by seek functions but how to do the seek work without the File class , with only the InputStream and Reader? I'm talking about the j2me midp 2 cldc 1.1 api, is there some methods or class to use for this thing? How could be implemented a binary search in a text file resident in the /res dir or the JAR or which could be the problems that cannot make possible this staff? If there was something like seek one way could be that one of decide a common length of words to read so going to the half of the text file it's possible with simply multiplication, and the do the binary search things.But for now I haven't found any resources or help.
    I hope you can help me to understand, thank you

    Hallo all,
    it is NOT the problem to locate the text I need to find in the fmb, or fmx.
    The problem is that since I want to change not only the text but also some more code around I want to do this in Form Builder - Object Navigator. And I'm not able to discover in which trigger or procedure the text appears.
    I do not want to edit fmx, or fmb in a text editor because I suupose theer are some checksums hidden for the format.
    BTW in FMT there is no code seen (only some binary) for v6i as it was in v4.5.

  • Binary search in files

    Is there a way of executa a binary search directlly over a file ? a java native way ?

    That would work best with a RandomAccessFile, since a binary search jumps back and forth looking at different places in the search space. And it would have to be a RandomAccessFile with fixed record lengths, sorted in the correct sequence. There is no method in the standard API to do that, but you could write the binary search code without much difficulty.

  • Extract text file from a folder and read the content

    I have "n" no.of text files saved in a folder with automatically generated naming convention which include DD/MM/YYYY and also some measurement output value.
    Eg: 1) Die_1_DUT_outputvalue_DD_MM_YYYY.txt
        2) Die_1_DUT_outputvalue_DD_MM_YYYY_ABC.txt
    In the above files part of the 2nd file naming convention same as the first file (i.e. Die_1_DUT and DD_MM_YYYY) whereas outputvalue is different and an additional string named ABC is appended.
    Now I want to search the 2nd file based on matching the naming pattern with the 1st file (note: the outputvalue in the file name is different for both files) and so far followed this method
    1) Use a list folder with *.txt pattern to search all the text files and the output is a 1D array
    2) then use array to cluster and then flatten to XML function to have all the text file names as a string element (not 1D array)
    3) then pass the output of the 2nd step to the sting match pattern and use a regular expression to get the required file name
    4) send the output of the 3rd step to search 1D array to get the index and then get the file name and later use read text file to read the content of the text file
    And I am stuck at the 3rd step while sending an input as the regular expression to match the pattern as the outputvalue in the namming convention of the above two files is different is there any way I can actually extract the filename/file?
    Any suggestions?
    1.png ‏11 KB

    Some bits in your code are unnecessary, a leaner implementation here:
    Beginner? Try LabVIEW Basics
    Sharing bits of code? Try Snippets or LAVA Code Capture Tool
    Have you tried Quick Drop?, Visit QD Community.

  • Find Change through external text file

    Hello folks
    I am bit pretty in InDesign scripting so could you please look into this.
    How can i change any particular text field in Indesign CS3 document from text file.
    I do have find change script but for each InDesign document specific text file is assigned.
    So each time i have to modify find change GREP property that is also repetetive of work. Is there any way to get find change information should be extract from external text file.
    Many Tanks in advance

    In the FindChangeByList script, you could customize the function myFindFile(myFilePath) {...} as to search the FindChangeList text file in the document location rather than the script location. That's an example. The question is: given a document, where will you have the corresponding FindChangeList?

  • Reading in text file

    I have a text file that contains something like this:
    <setting name="ip_address" serializeAs="String">
    I want to be able to search through the text file and based upon finding <setting name="ip_address" serializeAs="String">, I'd like to get the
    New to Labview.  So I'm not sure how to do it.  Currently using LabView 2012.  Thanks.

    Sebastian2011 wrote:
    I have a text file that contains something like this:
    <setting name="ip_address" serializeAs="String">
    I want to be able to search through the text file and based upon finding <setting name="ip_address" serializeAs="String">, I'd like to get the
    New to Labview.  So I'm not sure how to do it.  Currently using LabView 2012.  Thanks.
    Generally, your txt file will be read in as a spreadsheet string or as an array of strings.
    You can use Match Pattern to look for <setting name="ip_address" serializeAs="String">\r<value>
    Three outputs will contain the text leading up to the search string, the search string, and the rest (the rest will contain the ip_address followed by the rest of the text file),
    Use Match Pattern again looking for </value> that comes after the ip_address.  The first output will contain the ip_address.

  • Text file vs labview

    Hi. I have a text file of data ( please, look at the attachment) and  i want to create a single photoelectron's time spectra. I'm studying the transit time: i want to understand and characterize photomultiplier tube response to various signals. My teacher sent me that text file. I have create charge spectra by matlab ( charge spectra at 1651 V, 1710 V and 1580 V). But I can't use labview to create this time spectra ( i can't use functions tools and other ones). I need to convert 1-8192 channels in time, so  i could create Transit Time Histogram. So, could  you help me to convert x - axis ( in attachment is the channels number 1-8192) in time? I need create a data chart ( with data in my text file) in labview...thanks anyway.
    TIME SPECTRA 1651 Volt.txt ‏25 KB

    Today seems like an Example Finder day for me and my suggested solutions.
    LabVIEW can quite readily perform the tasks you need.  If you open the Example Finder, available in the pull-down menu under Help >> Find Examples... then and search for "read text file", "Histogram", and "graph" you will find general examples to do what you seek.
    Wire Warrior
    Behold the power of LabVIEW as my army of Roomba minions streaks across the floor!

  • Removing data from a text file

    i am trying to create a mehod which will take the values from two combo boxes
    , search through two text files in order to retrive the values, and then delete them from the file
    i am trying to use the following code to achieve this
    public void ReturnBook(){
         inFile1 = new BufferedReader(
         new FileReader(MemberIssueFile));
         inFile2 = new BufferedReader(
         new FileReader(BookIssueFile));
         outFile1 = new PrintWriter(
         new FileWriter(BookIssueFile),true);
         outFile2 = new PrintWriter(
         new FileWriter(MemberIssueFile),true);
         for(int a=0; a<MemberIssueFile.length(); a++) {
    }but i am getting the following compiler error
    cannot resolve symbol
    symbol : method get (int)
    location: class
    cannot resolve symbol
    symbol : method remove (int)
    location: class
    can anyone please show me where i am going wrong

    This error may occur when a method is called incorrectly: either its name is misspelled (or upper-lower case is misplaced), or a method is called with wrong types of arguments, or a method is called for a wrong type of object or a wrong class. For example, the same error, will be reported if you write
    instead of

  • Binary search tree - writing to a file in alphabetic order words from tree

    I have written a program that will read a list of words from a file, insert these into a binary search tree, write words from the tree to another file, so that the resulting list contains words in ascending order. My input file Alpha1.txt contains the following contents in the order and format given (one word per line):
    My program is supposed to be producing an alphabetical list of these words in another file "final.txt".
    Instead it gives me the following list:
    Dave Beth David Gina Cindy Sue Pat Mike Dawn
    This is obviously wrong, right? My correct list in "final.txt" should be
    Beth Cindy Dave David Dawn Gina Mike Pat Sue
    I am not sure what is wrong with my code which I reproduce below:
    import java.util.*;
    //read Java Developer's Almanac from
    //Read this:
      print node.value
      if node.left  ? null then preorder(node.left)
      if node.right ? null then preorder(node.right)
    public class AlphabeticBinarySortTree
         private static TreeNode root;
         private static TreeNode runner;
         static String[] alphaArray;
         static int alphaCounter;
         private static TreeNode alphaRunner;
         //Inner class
              private static class TreeNode
                   String word;
                   TreeNode left;
                   TreeNode right;
                   int count;
                   public TreeNode(String word)
                        this.word = word;
                        left = null;
                        right = null;
                   public void insertAll(TreeNode newNode)
                        if(newNode.word.compareTo(runner.word) < 1)
                             System.out.println("newNode.word = " + newNode.word);
                             if(runner.left == null)
                                  runner.left = newNode;
                                  runner = runner.left;
                        else if(newNode.word.compareTo(runner.word) > 1)
                             System.out.println("newNode.word = " + newNode.word);
                             if(runner.right == null)
                                  runner.right = newNode;
                                  runner = runner.right;
                   }// end method insertAll
                   // Recursively print words (with counts) in sorted order
                     public static void printInPreOrder(TreeNode root)
                             System.out.println(root.word + " ");
                             if(root.left != null)
                              if(root.right != null)
                       } //end method printInPreOrder()
                     //called from inside main
                    public static void arrangeInAscendingOrder(TreeNode root, PrintWriter pWriter)
                             if(root.left != null)
                                   arrangeInAscendingOrder(root.left, pWriter);
                             System.out.println(root.word + " ");
                             pWriter.write(root.word + " ");
                             if(root.right != null)
                                  arrangeInAscendingOrder(root.right, pWriter);
              }//end inner class TreeNode
         public AlphabeticBinarySortTree()
              root = null;
         //belong to the outer class
         public static void main(String[] args)
              System.out.println("This program reads text from a file that it will parse. ");
              System.out.println("In doing so, it will eliminate duplicate strings and ");
              System.out.println("pick up only unique strings.These strings will be in a ");
              System.out.println("stored in alphabetical order in a binary Search tree before they are ");
              System.out.println("written out to another text file in alphabetic order");
              //open the file for reading
                   BufferedReader bReader = new BufferedReader(new FileReader("Alpha1.txt"));
                   String words;
                   int count;
                   //System.out.println("A test to inspect the contents of words: " + words);
                   //System.out.println("Words =" + words);
                   count = 0;
                   //why is there an endless loop when
                   //I use "while(str != null)
                   StringTokenizer st;
                   st = null;
                   //based on
                   while ((words = bReader.readLine()) != null)
                        st = new StringTokenizer(words);
                            String token = st.nextToken();
                            System.out.println("Token = " +token);
                            //count the number of tokens in the string
                        }//end inner while
                   }//end outer while
                   System.out.println("Here are the contents of your tree:");
                   //System.out.println("before the call to print()");
                   System.out.println("the no of words in the file is: " + count);
              }//end of try
              catch(IOException exception)
                             FileWriter fWriter = new FileWriter("final.txt");
                             BufferedWriter bWriter = new BufferedWriter(fWriter);
                             PrintWriter pWriter = new PrintWriter(bWriter);
                   catch(IOExcepion exception)
         } // end main here
         //this method belongs to the outer class
         static void initiateInsert(String word)
              //TreeNode is also static by the way
              TreeNode newNode = new TreeNode(word);
              if(root == null)
                   root = newNode;
                   System.out.println("root.word = " + root.word);
                   runner = root;
         // Start the recursive traversing of the tree
            //without the access specifier 'static'
            //I would get the following error message
            // non-static method print() cannot be referenced from a static context
            public static void print()
                //System.out.println("**********AM I INSIDE THE PRINT() METHOD? ********");
               if (root != null)
                    //System.out.println("++++++++ AM I INSIDE THE IF BLOCK OF THE PRINT() METHOD? +++++++");
                    //System.out.println("Inside THE IF BLOCK OF print() BUT BEFORE THE CALL TO printInPreOrder(),root.word = " + root.word);
                  //open the file for writing
                                             FileWriter fWriter = new FileWriter("final.txt");
                                             BufferedWriter bWriter = new BufferedWriter(fWriter);
                                             PrintWriter pWriter = new PrintWriter(bWriter);
                                             AlphabeticBinarySortTree.TreeNode.arrangeInAscendingOrder(root, pWriter);
                              catch(IOException eException)
               }//end of if block
            } // end of method print
    }//end outer enclosing class here--------
    All help is highly appreciated. Thanks for your time and consideration.

    You suggest that I do away with the inner class
    then?Absolutely. In fact I strongly suggest this. You are learning how to code and need to do things cleanly and in small steps. That means first creating your Node class and making sure it works. Then creating your Tree class, and making sure it works. In fact I would load the Strings into the Tree class first directly and testing things before even thinking about reading to and from files. Only then should you implement the file input and output steps.
    The key here is that you don't go on to the next step until you're reasonably sure that your current code works. Remember, it's MUCH easier to code than to debug.

  • Text files showing up as binary in Yosemite

    Anyone having trouble with text files?
    I have a dumpster of text files in which I keep a lot of general information, including lots of knowledgebase items I keep handy.  I have my text files set to open with TextWrangler.   I've used this as the main way I work since 10.6 -- I search with Alfred/Spotlight, and GREP search text files with TextWrangler.  This is the way I keep lots and lots of general notes that I need to reference.
    Well, with Yosemite, it previews all previous plain .txt files as binary, or at least that's what it looks like.  When I open and save them, they are now binary static/noise, and that's how they save.
    If I create a brand new text file and save as a .txt file with TextWrangler, then everything is fine.
    I don't think this is TextWrangler's fault, because previewing/opening files with other text editors, such as even TextEdit, still shows binary.
    As described above, this is pretty much a baseball bat right into my spokes.  It makes Yosemite unusable for me.

    The general approach at this time is to ask if you've checked for any problematic fonts (all languages) with Apple's Font Book (look in the Applications folder). Find and remove all duplicates also.
    Start there to be sure all fonts that are in play come out with a clean bill of health.
    Also, don't hesisate to perform wholesale deletion of old and/or little used fonts - be skeptical of anything that has come from Office 2008, including those related to an Equation Editor installation.
    By all means be sure your 3rd party apps are Snow Leopard compatible and know the rumors are that 10.6.2 will be play better w/fonts in some cases.

Maybe you are looking for

  • Action infotype enhancement

    Hi All I have to enhance infotype 0000, when there is a hire action or leaving action, an Email notification should be send to IT/ Facilities, with a proper text. my question is 1. Does any body have idea which user exit or BADI I can use 2. how can

  • How to create trusted emails in java

    Hey guys, I need to create trusted emails with java using 509 certifications, can anyone tell me how can i do this or perhaps give me some direction? Thanks on advance.

  • The "Apps" button has disappeared from my iTunes

    I used to click on it and download app updates. Where has it gone?

  • Inman Article: Software will protect MLS data from cyber thieves

    Distil Networks will soon shield property search apps from data theft - Distil Networks closes $21M funding round Distil Networks has kept "bad bots" from stealing multiple listing service data from property search websites. Coming off a $21 million

  • Bizarre screen artifacts occurring

    Strange issue I'm having with my 2007 Macbook. Running Snow Leopard 10.6.3. The screen begins to glitch out whenever the OS displays the shadows around window boxes and I get these bizarre artifacts. I made a Picasa Gallery to show all the screenshot