Effecient way to edit a file in Java

I'm writing software for my company that is basically a primitive database (using a text file) to store entries for people that have filled out a warranty card. Right now the list is very small, less than 1000 entries, so access times don't cause very noticeable delays, but I wanted to build the program so that once the list grew, my algorithm's inefficiencies didn't cause big delays.
Right now I have it so when a new entry is added, it simply adds it to the end of the file, so that's O(1). Searching for a file is O(n) (searches from beginning of file to the end until a match is found, which I know that can be improved with startup sorting and changing algorithms, something I am working on).
Right now I'm trying to think of an efficient way to edit an entry in the file. Obviously first the entry has to be located to be edited, so that part will be patterned after my search algorithm. But after locating the entry, what's the best way in Java to edit that line? The best option I can think of right now is to load the whole text file into memory, make the change, and replace the original text file with the one stored on memory. But that seems like a lot of overhead just to edit one line. Is there a better algorithm I am overlooking? Thanks ahead of time.

jrobinson3k1 wrote:
The best option I can think of right now is to load the whole text file into memory, make the change, and replace the original text file with the one stored on memory. But that seems like a lot of overhead just to edit one line. Is there a better algorithm I am overlooking? Thanks ahead of time.That's what all text editors do. That's what you do yourself when you want to change one line of your source code. If changing the line of text can change its length (which normally it can) then you have the best algorithm. Except of course for the database. You have the best algorithm that can be implemented in the next couple of days, let's put it that way.

Similar Messages

  • Is there any easier way to edit imovie files that have been exported as mov file then added to FCE 4?? As every move I make has to be rendered and takes forever??? Also my recording is going out of focus without me touching the camera, why has this happen

    Is there any easier way to edit imovie files that have been exported as mov file then added to FCE 4?? As every move I make has to be rendered and takes forever??? Also my recording is going out of focus without me touching the camera, why has this happened any idea what causes this??
    iMovie '08, Mac OS X (10.5.8), FCE 4

    My daughter has had her Razr for about 9 months now.  About two weeks ago she picked up her phone in the morning on her way to school when she noticed two cracks, both starting at the camera lens. One goes completely to the bottom and the other goes sharply to the side. She has never dropped it and me and my husband went over it with a fine tooth comb. We looked under a magnifying glass and could no find any reason for the glass to crack. Not one ding, scratch or bang. Our daughter really takes good care of her stuff, but we still wanted to make sure before we sent it in for repairs. Well we did and we got a reply from Motorola with a picture of the cracks saying this was customer abuse and that it is not covered under warranty. Even though they did not find any physical damage to back it up. Well I e-mailed them back and told them I did a little research and found pages of people having the same problems. Well I did not hear from them until I received a notice from Fed Ex that they were sending the phone back. NOT FIXED!!! I went to look up why and guess what there is no case open any more for the phone. It has been wiped clean. I put in the RMA # it comes back not found, I put in the ID #, the SN# and all comes back not found. Yet a day earlier all the info was there. I know there is a lot more people like me and all of you, but they just don't want to be bothered so they pay to have it fix, just to have it do it again. Unless they have found the problem and only fixing it on a customer pay only set up. I am furious and will not be recommending this phone to anyone. And to think I was considering this phone for my next up grade! NOT!!!!

  • What the best way to create XML files from JAVA application?

    Hi to all,
    I need to edit and to create new filex in format of xml. I know to parse, but what would be the best way to do:
    1. - Create new file, create like simle text file, or there is some clases that know to do it in more simple way
    2.a - Edit XML file, to take some data and add it to the XML in the place I want to.
    2.b - Also Edit, but not to add fields, just update some of them.
    Code examples or links to samples woul be welcomed.
    Best regards, Nick.

    I have tried working with XML directly using the Java classes but this was a pain. I then looked at DOM4J and JDOM and found JDOM easier to use.

  • The nicest way to generate xml-files by Java???

    I have to generate huge and quite complex xml files by Java. I have to fetch the data from a Oracle database. What I really don't know is a proper and reliable way to this? I could of course create a String and concatenate all the tags, attributes and data but it doesn't feel right. I guess this is a quite common task and there are many established ways to this by Java. My question is what is the best way to this? What is your suggestion?
    Thank you for any clues...

    Hi,
    Since you have access to the database, I think one of the best way is to create stored procedures that will generate those files for you (using SQL/XML functions preferably) and return the content to the Java caller.

  • Edit HTML File using java

    Hi....
    I have a report in HTML format and a list of thresholds in txt format.
    Now, using java how can I:
    1. Compare the values in the report with the thresholds
    2. Edit the report such that values over the thresholds are highlighted in say, red colour.
    I am new to Java programming, so java jargons won't be of much help. I read about jeditorpane but it's primary use is to display html file(that is what i inferred). Is their a way in which i could accomplish the above using jeditorpane??....how do i do the comparison part??

    srgsoroka wrote:
    Did you check http://jtidy.sourceforge.net/.
    From site:
    "JTidy is a Java port of HTML Tidy, a HTML syntax checker and pretty printer. Like its non-Java cousin, JTidy can be used as a tool for cleaning up malformed and faulty HTML. In addition, JTidy provides a DOM interface to the document that is being processed, which effectively makes you able to use JTidy as a DOM parser for real-world HTML."Yes, I did. But I don't need a syntax checker.The syntax is alright. I want to modify the HTML code after comparison with a txt document.As far as DOM parser is concerned, I googled the term but didn't understand much of it..:-(...If you could explain it in layman's terms........

  • Is there a way to edit raw files from the Canon 5DMkIII in Lightroom 2?

    I rented a Canon 5DMkIII this past weekend and shot in RAW. I'm running Lightroom 2.7 on my laptop because I have a pre-Intel dual-G5 tower at home and can't run LR3 or LR4 on a pre-Intel chip machine and I tend to share my libraries across my laptop to my tower and back (so I need to be able to open the LR files on both machines, which is why I'm still using LR2 ... I know, I know, I need to upgrade but that's going to be a hefty investment!)... In the meantime, I'm wondering if there's a way to view/edit the raw files in Lightroom? They won't even import (I get the message upon import attempt: "Some import operations were not performed. (97)")... I know the information is there, though, because I used PhotoMechanic to do the initial sort of my images that I wanted to keep/edit. I see there's ACR (Adobe Camera Raw) 6.7 (I think it is) that supports the 5DMkIII, but I'd prefer to edit across the board in Lightroom, it's so much faster. Is there something I can download to still edit my raw files in LR2? Or, do I have to buy the update and get LR4 if I want to edit my 5DMkIII RAW files? Thanks in advance for your help!!

    Support for the canon 5d Mk111 was introduced in LR 4, ACR 6.7 so you will have to use the Adobe DNG Converter 6.7 or later to convert the raw files to dng format before you can import and work with the files in LR 2. The converter is a free download from Adobe and is available at this link.
    Mac http://www.adobe.com/support/downloads/detail.jsp?ftpID=5485
    Win http://www.adobe.com/support/downloads/detail.jsp?ftpID=5486

  • I need to know best way to edit MXF files, with least rendering, is that converting the MXF or Log and Transfer? the end product is dvd, but I have lots and lots of these projects to do.

    I am about to comence my Edit, and was told of Mpeg Streamclip, however this doesn't seem to work with my Canon XF305 Clips, the reason I was told to use it was so I wouldn't have to Render in Final Cut Pro all the time.. I do have the Canon Disc with the Plug in Utility and the update from their site.
    Is it best to Convert these MXF files first and import them into FCP or use 'Log and Transfer', so far I am unable to do either!!
    The projects on the timeline will have introduction .Movs already on it as a Template to re-use again and again with the new Footage ( MXF Files ) to be added and edited with transitions etc..This process is repeated again and again but with different MXF clips each time.
      I am looking for the quickest and best way for workflow as there are 80 or more projects to do, each with 10 or so clips to be added to the timeline and Exported for DVD...Will I have to then Compress to fit onto DVD's??
    I know Streamclip is an Mepeg 2 app but I thought the Canon XF305 Shot as mpeg2....
    Is Log and Transfer my only Option?
    Basically I need to know the quickest for Render purposes, and of course, the best way so the files aren't so huge etc etc.
    Please, any suggestions would be greatly received....

    We only work with PR422 files in FC7.  We use Shane's workflow with all 5D & MXF footage.
    Make your life easier and stick to the ProRes family for your footage and edit sequences. Avoid H264 & convert any you have to ProRes.
    Unless you are considering Blu-Ray the only way to deliver video on a DVD is to convert it to SD.
    Depending on the length of your show you can make a Blu-Ray in Compressor but you have very limited authoring options when compared to DVD Studio Pro.
    Compressor can also convert your HD to SD mpg-2 & Ac3 files. The best results usually come from setting the frame controls in the mpg-2 setting of Compressor to best. Depending on the the length of the show and your Qmaster settings this can take quite a while.
    I personally find Compressor's HD to SD DVD conversion varies. Sometimes it is wonderful and sometimes not so much. I prefer the following as it is usually is faster and very consistent.
    Export a quicktime movie (not QT conversion) of your final sequence
    Import the exported HD file back into FC.
    Create a SD 16x9 sequence and then drop in the recently exported HD seq and render. Rendering the sequence basically has FC doing the HD to SD conversion. Export the SD sequence and then convert to mpg-2 & ac3 in Compressor. While this does take time I still find it faster than Compressor with Qmaster utilizing all cores.
    Another option is using jobs in Compressor
    http://pixelcorps.cachefly.net/macbreak-154-540p-h264.mov
    In this workflow you would have Compressor convert the HD file to SD and then through jobs convert the SD file to mpg2 & Ac3. 
    In theory the jobs version could be faster (based on a number of variables- length, Qmaster, etc) but I haven't had time to compare the two. 

  • Best way to copy/move files in Java...

    I am trying to write or use Java to create directories on the filesystem, based on user information to a servlet. Using the File object and calling the mkdir() method, this works really well. I would like to add the functionality of then moving several files from an existing directory to this new one.
    I can certainly write some code that uses the Runtime.getRuntime().exec("cp a.html b.html")and issue a system command, but if there's a better way, I'd appreciate it.
    Thanks,
    Jay

    If you are implying that he use th renameTo() utility
    of the File class, then that will only work when the
    underlying system allows it - E.G., no renames across
    mount points, hard drives, partitions, etc. Copy the
    file yourself (with 7 or 8 lines of code) and avoid
    the whole thing.I would be willing to accept these restrictions, but I never would have guessed that the renameTo() method would copy the file. That doesn't seem to make sense.
    So you think I should just write code that issues a system command. I was hoping to avoid that because I dev and test on my Windows machine, then deploy to Unix. Is there nothing out there that handles file copies?

  • Correct Way To Edit Sudoers File

    I would like to grant non admin users the ability to run:
    /sbin/shutdown
    On my test machine I ran the command visudo. At the bottom of the file there seems to be an example of how to allow anyone in the group "users" on localhost to run the "shutdown" command. I uncommented out this line.
    %users localhost=/sbin/shutdown -h now
    I then logged in as a non admin user. I ran the command
    sudo -l
    It told me that the current user is not allowed to run sudo. After doing a bit of web search I came up with the following command that I added to the bottom of the sudoers file:
    ALL ALL = NOPASSWD: /sbin/shutdown
    I then logged in as a non admin user. I ran the command
    sudo -l
    User XXX man run the following commands on this host:
    (root) NOPASSWD: /sbin/shutdown
    I just want to make sure that this is the correct way to do this. From what I found on line it would seem that any user could run shutdown on any host and that is not what I want.
    One last question is, the machines are set up to NetBoot. The machine contain no internal drives. I just want to make sure that users will only be able to shut down a machine they are logged into. Thanks for all the help in advance and sorry if the question is a bit noobish.

    I think I had to do something like this a while back. Let me look though my records and see if I can dig anything up.
    PowerBook G4   Mac OS X (10.4)  

  • Best way to edit PHP files in FB4?

    I'm trying out FB4 and would like to be able to use a PHP editor within the FB application. At the moment the PHP files it generates open up in Dreamweaver, which is fine but it would be better to have one tool than two. I tried to install the Eclipse PDT but I don't see any more options after I've installed it. I really would like nice coloured formatting and maybe code assist, like DW provides. Has anyone done the same? (Also interested in the same thing for FB3).
    Thanks

    I found the PHPEclipse plugin, which installed into FB4 - will try it with FB3 now

  • I want to Edit PDF file using java(urgent)

    if any body helps me i shall be thankful to him.
    its urgent i hav to complete my assignment.

    http://www.geocities.com/marcoschmidt.geo/java-libraries-pdf.html
    http://www.firehouseinternational.com/usersite/uniforms/uniformsproduct.asp?categoryid=8787&productid=13454&page=1

  • Is there any way to create installation files using java

    Hi,
    can we create write any program to install our product in linux. I thnk we can do it using VJ++, but for windows.
    thanq
    chandu

    can we create write any program to install ourproduct in linux.
    Yes, you can write any program to install your
    product in linux.Visual J++ might not really be the best choice though.

  • Creation of .RTF file in java

    Hi,
    I want to create/edit .RTF file through java application. In my RTF file, I should be able to edit data(formatting), inserting tables. This is already done. Now I want to create chart (like pie-chart) using java. I searched the net for the last couple of days but I couldn't get the proper help. I can do that in SWING but its of no use.
    can anyone help me in this?
    Thanks & Regards,
    mrP

    Hi,
    Can someone please point me in the right direction? I'm trying to create an RTF file from data in a database, so I have no need to use JTextPanel or any GUI components. I've been trying to use the RTFEditorkit with a DefaultStyledDocument, but can only manage to insert one line into the document(!) Does anyone have any suggestions or examples that would explain how to do this?
    Any ideas would be appreciated.
    Thanks in advance,
    Gillian

  • Accessing XML files through java

    Can any one explain me the easiest way of accessing XML files from Java.

    Hi,
    If you want to only access the XML file, use the SAX parser It will be very easy to handle and identify the element and value.
    else if u want to change the XML value also, then better go with DOM, Which has very good flexiblity.
    use according to the need, let me know if any help is required......
    With Cheers
    PrasannA

  • Editing pages files in Linux

    I have a bit of a problem.
    I have several files as .pages documents and I need to edit these in Linux.
    (Kubuntu 9.10, fully updated)
    now I can save the .pages files as .odt and open them in OpenOffice.Org
    but, I have some markup that open document text files don't support.
    but that is kinda importaint markup.
    is there a way to edit the files on Linux, or a other file type I can use that I can open in linux without losing markup?

    now I can save the .pages files as .odt
    How? Only .doc and .rtf and .pdf and .txt are available for me.
    is there a way to edit the files on Linux
    Not .pages
    other file type I can use that I can open in linux without losing markup?
    I think .doc and .rtf and .pdf are your only choices.

Maybe you are looking for