Reading file like hashmap (datamap)

Hi,
I am wondering if we can extract a record from a file using a key.
Say I've a file with the records like this
test1 this is test one
test2 this is test two
test456 this is test 456
Now is there a way where I can read the record directly by giving the key (which is test1 or test2...)
If i give test2 as my key I shoulod get "test2 this is test two"
testVariale = SampleTest.getValue(test2);
display testVariable should be giving "test2 this is test two"
Please let me know if there is a way. I greatly appreciate your help.
Thank you very much in advance.
Java Raider

Well, read lines from the file until the key matches the start of the line.
If the file is sorted, you can do a binary search.
I don't know if this has already been written, if that's what you're asking.

Similar Messages

  • I just got an iTouch and whenever I try to sync it to iTunes it keeps poping up with a message that says something like "cannot sync or read file". What should I do?

    I just got an iTouch and whenever I try to sync it to iTunes it keeps poping up with a message that says something like "cannot sync or read file". What should I do?

    Is the error message:
    "Attempting to copy to the disk <iPod name> failed. The disk could not be read from or written to."
    if it is try:
    http://support.apple.com/kb/HT1207
    If not, what is the wording?

  • OutOfMemoryError while attempting to read 60MB file into HashMap objects

    Hi,
    I've a 60MB file with about 60000 records that I'm trying to read into a HashMap of <String, String[]>. However, as far as I can see it can only manage reading in 12000 before it falls over with an OutOfMemoryError.
    My eclipse.ini contains the following entries:
    -Xms40m
    -Xmx512m
    I've changed Xmx512m to Xmx1024m but this hasn't made a difference.
    My program involves reading in the file, sorting it based on 2 attributes of a record and then outputting it in the sorted order.
    I've tried a few other methods around just reading in the attributes that I need, doing the sort with those, looking for the rows I need from the input file sequentially and then outputting this in the correct order but this seems to be taking forever, well over 12 hours!
    How else can I go about this? Thanks.

    Here is the code. Sorry, how do I go about compiling this class as it's looking for the CsvReader jar but can't find. Have tried the -cp option but doesn't seems to work. Thanks.
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.io.IOException;
    import java.util.HashMap;
    import com.csvreader.CsvReader;
    public class Reader {
          * @param args
          * @throws IOException
         public static void main(String[] args) throws IOException {
              CsvReader reader = new CsvReader(new FileReader("C:\\temp\\gen_ppl.csv"), '|');
              HashMap<String, String[]> allCorpIDs = new HashMap<String, String[]>();
              while(reader.readRecord())
                   allCorpIDs.put(reader.get(0), reader.getValues());
    }

  • I cannot open some pdf files online with Reader XI (like sample forms in Help section).

    I cannot open some pdf files online with Reader XI (like sample forms in Help section or IRS.gov or credit card statements).  I have uninstalled Reader XI, cleaned and reinstalled.  I have no problem right-clicking and downloading and then viewing the files.  No problem viewing acrobat files.  I'm runnnig Windows 7,  IE9.     I can acces them through Chrome.

    RESOLVED
    I found two suspect programs that were installed within the last 48-hrs that may have caused the problem
    1) - Libre Office - latest update.  This is a fork of Open Office.  (unlikely)
    2) - ManyCam video manipulation software  (likely)
    Following info here, I opted to try to open an Adobe PDF file that was on my hard drive.  When I did, it refused and IE10 gave me an ActiveX error (AHA!!).   When I checked the installation of ManyCam, it had installed a version of DirectX that may have over-written the resident versions or disabled them somehow.
    I uninstalled ManyCam but left Libre Office's update in place, then I ran a system restore from a point 24-hrs before the installations.
    This resolved the problem 100%.
    So, the suggestion here is that there may be one or more program in the wild that is interupting the ActiveX or DirectX systems.  They may be running or installing an older version.  In this case it appears the handlers were broken.
    Once the system restore had completed I was able to open Adobe PDF files within my IE10 browser from the Internet as well as open PDF files from my hard drive.
    Note that this same issue also clearned up a problem I was having with the Comodo Dragon web browser, which is a fork of the Chrome project.  Once I eliminated the suspect program and ran the system restore all was well.  In the instance of the Comodo browser it was unable to open or reach anything - dead white screen below the menu bar.
    So my suggestion would be to take an inventory of recent program installations, remove/uninstall them, run system restore from a date before the suspect programs were added, and see what happens.  In my case that fixed the problem.

  • Recursive reading of a file (like tail -f)

    I'm trying to recursively read the contents of a file that is simultaneously being written to; esentially emulating tail -f in AppleScript. Any examples I could be pointed to?
    My AppleScript application issues a 'do shell script' that returns data as the script executes. So I can wait for the script to finish and display the results, how my app currently works (less than ideal), or I can have the shell script write to a temp file and then iteratively read and display the contents of the file as it fills up with the shell script's output (ideal).
    Problem is, I don't know how to tell if the temp file has finished being written to, and therefore when to stop reading into my display field.
    Trying to get my head around this - any thoughts, tips and/or examples would be much appreciated -- thanks

    There's several ways of doing this. The most obvious solution is to have your script write out some text that indicates the end of its processing, to which your AppleScript can react and know the script is finished. For example, if the script wrote out the string "done" at the end, it's trivial for AppleScript to check whether the last line in the file is 'done' or not.
    The alternative appoach is to capture the PID of the shell script and periodically check to see if that PID is still running. When it no longer appears in the process table you know you're done. For example:
    <pre class=command>set thePID to do shell script "/path/to/length/script &> /path/to/outputfile $!"</pre>
    the $! is a shell flag that returns the PID of the process you just started. Now you can do something like:
    <pre class=command>set thePID to do shell script "/path/to/script > /var/tmp/outputfile 2>&1 & echo $!"
    -- now thePID will hold the PID o the /path/to/script process
    set charsRead to 0
    try
    repeat
    do shell script "ps -p " & thePID
    set theProgress to read file ":private:var:tmp:outputfile" as text
    set numChars to number of characters in theProgress
    display dialog (text (charsRead + 1) through numChars of theProgress) giving up after 1
    set charsRead to count theProgress
    end repeat
    end try</pre>
    This launches the script and captures the PID. It then repeats through a loop that checks if the PID is still running. If it is, it reads the file and displays the chunk of the file that hasn't yet been seen (using the 'charsRead' variable to keep track of how much has been seen.
    If the PID is not running, the 'ps' shell script returns an error, which terminates the try block.

  • How can I save adobe reader file from gmail into my adobe reader app?? i would like to open one file in place where I'm not able to access internet and for that reason i would like to save it. is that even possible?

    How can i save adobe reader file from my gmail into my adobe reader application. or is there any other way i can save it into my phone so I'm able to open in any situation not just from my gmail???

    Long hold on the document in mail and it should give you the open in... option, select adobe reader and the file is now saved locally for viewing even while offline.

  • How to view PDF files like a flipping magazine?

    Hi, I am new here. I didn't know if it is the optimum catagory for my question, I hope you guys will help me.
    In brief, I want to view PDF files like a flipping magazine. You know, just the same flipping effect that ibook did on ios. Adobe reader is the only choice to browse PDF on computer for me. It's kind of bothering and annoying now.
    So, any ideas for that? Plus, my computer runs on win7 64bit.

    This is also a good site:  http://www.issuu.com/  You can sign up and use it for free or you can upgrade(for a price) to make custom changes (like background color, button color, etc.)  You can also embed the html code into your website if you would like someone to view it there.  Good luck!

  • Read file from URL and save to FTP

    Hi,
    I have worked in java few years back, now I am out of touch. My friend asked me to create an applet program for him which he can use to download a file from remote location to his ftp server.
    For e.g.
    File
    http://www.demo.com/filename.avi
    Saved to
    ftp://username:password@ftpsite_address/foldername
    I was searching for the classes which I can use to achieve this functionality.
    To save to FTP
    URL url = new URL("ftp://username:[email protected]/folder/filename");
    URLConnection urlconnection = url.openConnection();
    long l = urlconnection.getContentLength();
    OutputStream outputstream = null;
    outputstream = urlconnection.getOutputStream();Using the above code I can get the outputstream to which I can write.
    I am now stuck here, have some doubts.
    What all classes should I use to read a file like
    http://www.demo.com/filename.avi
    I know I can use URL to open connection to URLS and then streams to read the url.
    I am interested in knowing the class which I should use to read any type of file. File can be zip/avi/rar or anything else.
    What all method of the class should I use to read the file which will support all type of files.
    Which classes should I use to write the files. The files are going to be huge in terms of size.
    I have searched everywhere but every place different classes are used.
    Any help is appreciated.

    Ok now I have started coding but facing a problem.
    [PHP]try {
         URL url = new URL("http://url_to_file/test.txt");
         URLConnection urlconnection = url.openConnection();
         long l = urlconnection.getContentLength();
         fTextArea.append("Content Length = " + l);
         BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
         String line;
         while ((line = in.readLine()) != null)
              fTextArea.append("\n"+line);
         in.close();
    } catch (Exception e) {
    fTextArea.append(e);
    return;
    [PHP]
    When I run this code locally it works fine but when run in browser it shows security exception
    java.security.AccessControlException: access denied (java.net.SocketPermission site:80 connect,resolve)
    What should I do to resolve this error. Sorry for being such a noob but do not have much info about this.

  • How to combine both DAQ AI signal, write and read file in single VI

    Hi
     I am the new user of LabVIEW version 7.1 for testing automation application. I have to measure 33 signals ( mostly analog like temp, pressure, etc...) from NI USB 6210 DAQ system and write in master file for future verfication.From real data or from master file back up have to write  one more file if only the signal reaches steady state , which will used for analysis and same signals to be read from this file parallely & make a waveform and/or table display format.
    Pl. help me to shortout this problem 
    note: I have plan to ugrade labVIEW version 2011 shortly, so let me know doing parrel acquistion write and read file for data analysis in same VI in version 7.1...... 

    Parallel operations in LabVIEW are very simple.  Just code it in parallel and it will work.
    Try taking a look at some of the examples in the NI Example Finder (Help > Find Examples).  There you will find example for writing to and reading from files, as well as data acquistion in parallel with other operations.
    You might need a producer/consumer architecture is you are acquiring data very quickly.
    Chris
    Certified LabVIEW Architect
    Certified TestStand Architect

  • How can I quickly view pdf files like I can do with Windows Picture and Fax viewer for jpg files?

    How can I quickly view pdf files like I can do with Windows Picture and Fax viewer for jpg files? I need to look at several thousand PDF files. It takes too long to open each one individually. The only thing I could think of is combining them into large groups and then using the Navigation index. But I like the way windows Picture and Fax Viewer does it because you can keep the files separate. Combining PDFs causes loss of individual file names. That would be a problem since I do need to have the individual file names.

    Windows Picture and Fax Viewer is a DLL and is started via a rundll32.exe call and can't be set as an application to handle images in Firefox 3 and later versions.
    Try to set Windows Picture and Fax Viewer as the default viewer in Windows, then it should be listed automatically in the Mozilla Firefox Browse dialog.
    *http://www.winhelponline.com/articles/115/1/Windows-Picture-and-Fax-Viewer-as-the-default-viewer-in-Mozilla-Firefox.html
    '''If this reply solves your problem, please click "Solved It" next to this reply when <u>signed-in</u> to the forum.'''

  • [Urgent] How to read files from different directories?

    I am new to Java Programming, I would like to know how to read files from directories other than the current one? (example as follows)
    ProjectDirectory
    |--MainDirectory
    |--MainProgram.java
    |--SupplementDirectory
    |--SupplementProgram.java
    |--Pictures
    |--Image.gif
    What should I write in the MainProgram.java so that I can use the supplementProgram.java from MainProgram and read the Image.gif file from the MainProgram.java?
    Thanks

    Run through the I/O tutorial here. It should get you up to speed on this sort of thing...

  • How do i make firefox automatically open a file. "Do this automatically with files like this from now on." does NOT work.

    I have firefox set to Open .wav files with VLC and i have the check box marked to "Do this automatically for files like this from now on." But every time i click download for a .wav voicemail from gmail, i get the same dialog box. I just want firefox to hand the downloaded file to VLC and play it. I don't want to have to click anything after i click the download link. Isn't that action what i'm telling firefox to do after i mark the checkbox with "Do this automatically with file like this from now on." ? Isn't that implied with my selection of the box? How can i fix this?i want to click a "download" link for a .wav voice mail in Gmail and have it automatically play in VLC without any further interaction from me.

    No it's saving the preferences and the check box remains checked from session to session. It will even continue to ask me to what to do with the file even in the same session when i try to download the same file again 5 seconds after i downloaded it the first time.

  • Can't figure out why the "Do this automatically for files like this from now on" is disabled Compressed (zipped) Folders

    I recently had to uninstall and reinstall Firefox. Now with the new version it will not allow me to click the check box "Do this automatically for files like this from now on". The line is disabled and a light gray. I went into the Applications tab under options and can't find the Compressed (zipped) Folders file type either.
    I download a bunch of files for work and to have to click is going to be the biggest pain. Any help will be greatly appreciated!!

    Screenshot:

  • How can I save a page and all its component parts in a single file, like IE does as an MHT - it's much easier for mailing to people where page address not available?? (as in output from an airline booking site, for example)

    how can I save a page and all its component parts in a single file, like IE does as an MHT?
    It's much easier for mailing to people where page address not available?? (as in output from an airline booking site, for example)
    It is simply too painful to have to zip everything up into a single file to send. MHT format has been available for years now from IE, and with every new FF release it's the first thing I look for. I have been using FF for years, and hate having to come out of it, over into IE |(which I even took out of startup) and key everything in again, in order to send somebody something in a convenient format that they can open with a single click.
    I can't believe this hasn't been asked before, so have you looked at it and rejected it? Have MS kept the file format secret?
    Thanks
    MG

    This is not really an answer just my comments on your question.
    I am sure I recollect efforts being made to get mhtml to work with FF.
    Probably the important thing to remember about .mhtml is that if other browsers do support it they may need addons, and may not necessarily render the content correctly/consistently.
    There are FF addons designed for archiving webpages, you could try them, but that then assumes the recipient has the same software.
    You could simply save the page from FF to your XP pc; then offline open it with and save it using IE, before then emailing using FF, and attaching the .mht or mhtml file that you have now created on your PC.
    As an alternative method, in some cases it could be worth considering taking a screen grab of the required page, then sending that to the recipient as a single email attatchment using either a bitmap or jpeg file format for instance.
    Something such as an airline booking may be designed with a print option, possibly it could be worthwile looking at sending the print file itself as an email attachment.

  • Firefox crashes whenever i want to install any addon or download any file. Some times i am receiving error while downloading any file like "could not be saved, because you cannot change the contents of that folder"

    I am the user of latest firefox 3.6.6 browser. I am getting problems of frequent crashes whenever i tries to install any addon. The crashes also occures whenever i want to download any file.
    I am also receiving errors while downloading any file like:
    "C:\Users\****\AppData\Local\Temp\******.001.part could not be saved, because you cannot change the contents of that folder.
    Change the folder properties and try again, or try saving in a different location. I already changed it many many times but still the same problem."
    Adobe flash palyer is also giving problems of not responding. I am using updated version of it already. Java is also updated.
    I already uninstalled firefox compeletly and re installed it many many times but still the same problem. I also scanned my computer with avira and malware bytes' Anti malware and got no dection. Please ractify this problem ASAP lest my profession will suffer.
    == Crash ID(s) ==
    b7f518f2-8d86-41ca-8bab-aee632100709; 1d790e10-d8eb-4904-98c9-94bc62100708; f042d319-b9f8-42ed-a8cb-57c7d2100708

    Please help.
    It is getting worse
    Adobe flash player is crashing. I already uninstalled and re installed the latest ver. Also it is hanging randomly.
    Please help.

Maybe you are looking for

  • IMovie HD won't launch with mytv.pvr pluged in to the USB bus

    I recently purchased te Eskape mytv.pvr. After installing it the iMovie HD would crash when launched. If I unplug the mytv.pvr, iMovie launched and works fine. When the mytv.pvr plugin, iMovie quit the the "The application iMove HD quit unexpectedly.

  • CRM employee (business partner) & org unit extraction question

    Hi all, I have a question regarding extracting business partner and org unit in CRM. Basically user wants to report on employee level and org unit level. When I looked at the org unit hierarchy datasource (0BBP_ORGUNIT_HR01_HIER), it does not include

  • Lightroom 2.2 and CS3 Panorama/Merge (Windows)

    Prior to a system crash, merge/panoramas worked flawlessly for me on a Windows Vista system. At the time, both LR and CS3 were on the same drives. Since the crash, I have the two programs on different drives and other than basic edits, all other opti

  • Servlet Instance Variable scope

    Just want to clarify my understanding of instance variables in regards to Servlets. public class TestServlet extends HttpServlet     public String instVariable = ""; public void processRequest(HttpServletRequest request, HttpServletResponse response)

  • Regasm.exe application error

    RegAsm.exe-Application error. The application was unable to start correctly Oxc0000005