What is the efficient way of insert some bytes into a file?

Hello, everyone:
If I want to insert some bytes into a file (for example, insert the bytes before all the original content of the file, or append the bytes to a file), and the size of the original file is very big. I am wondering what is the efficient way? Where can I get some sample codes?
regards,
George

Thanks, DrClap.
I have tried your method and you are correct. I have written a simple program which can be used to insert "Hello World " to the start of a file ("c:\\temp\\input.txt"), and I have verified that it can work. Please help to see whether it is correct and whether it has a more efficient way.
public class TestDriver {
     public static void main(String[] args) {
          byte[] back_buffer = new byte [1024];
          byte[] write_buffer = new byte [1024];
          System.arraycopy("Hello World".getBytes(), 0, write_buffer, 0, "Hello World".getBytes().length);
          int write_buffer_length = "Hello World ".getBytes().length;
          int count = 0;
          FileInputStream fis = null;
          FileOutputStream fos = null;          
          try {
               fis = new FileInputStream (new File("c:\\temp\\input.txt"));
               fos = new FileOutputStream (new File("c:\\temp\\output.txt"));
               while ((count = fis.read (back_buffer)) >= 0)
                    fos.write(write_buffer, 0, write_buffer_length);
                    System.arraycopy (back_buffer, 0, write_buffer, 0, count);
                    write_buffer_length = count;
               //write the last block
               fos.write(write_buffer, 0, write_buffer_length);
               fis.close();
               fos.close();
               //copy content back into original file
               fis = new FileInputStream (new File("c:\\temp\\output.txt"));
               fos = new FileOutputStream (new File("c:\\temp\\input.txt"));
               while ((count = fis.read (back_buffer)) >= 0)
                    fos.write(back_buffer, 0, count);
               fis.close();
               fos.close();
               //remove temporary file
               File f = new File ("c:\\temp\\output.txt");
               f.delete();
          } catch (FileNotFoundException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
               try {
                    fis.close();
               } catch (IOException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
               try {
                    fos.close();
               } catch (IOException e2) {
                    // TODO Auto-generated catch block
                    e2.printStackTrace();
          } catch (IOException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
               try {
                    fis.close();
               } catch (IOException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
               try {
                    fos.close();
               } catch (IOException e2) {
                    // TODO Auto-generated catch block
                    e2.printStackTrace();
}regards,
George

Similar Messages

  • What is the best way to insert massive data into an existing excel file?

    dear gurus,
    i am wondering that what is the best way to insert massive data into an existing excel file, more performance perspective.
    the file is read from BDS , and we want to insert data into it .
    the way i can think of is
    1. OLE AUTOMATION
       i think performance will be a big problem
    2. Office integration
        i am not sure it's facing the same performance issue ?
    3 . XXL_SIMPLE_API/FULL_API
        I am not sure whether they can insert data into an existing excel file?
    could you please give me some advices?
    br.
    jun

    Hi,
    If you want to APPEND data( add data to an existing excel file) from SAP, then use GUI_DOWNLOAD fm with APPEND = 'X' paramter.
    Best regards,
    Prashant

  • What is the proper way to insert an envelope into a hp9680?

    What is the proper way to put an envelope into a HP 6980?

    Hi,
    Normally th software (driver) will shows you how to feed tha envelop for example like this.
    Regards
    BH
    **Click the KUDOS thumb up on the left to say 'Thanks'**
    Make it easier for other people to find solutions by marking a Reply 'Accept as Solution' if it solves your problem.

  • What is the efficient way of working with tree information in a table?

    hi all,
    i have to design a database to store,access,add or delete(the tree nodes) the tree information. what is the efficient way of accomplishing it?
    let's assume the information to be stored in the table is parent,child and type(optional).The queries should be very generic(should be able to work with any database).
    anybody has any suggestions?I have to work with large data.
    quick response is highly appreciated.
    thanks in advance,
    rahul

    Did you check out this link?
    http://www.intelligententerprise.com/001020/celko1_1.shtml
    Joe Celko has really gave some interesting way to implement tree in a rdbms.
    Best wishes
    Anubrata

  • In Acrobat Professional 8, what is the best way to insert/combine multiple pdf's together in a large

    In Acrobat Professional 8, what is the best way to insert/combine multiple pdf's together in a large volume?
    We have 300 pdf reports and need to insert a 2 page cover page infront of each report. Not sure if Batch processing is best???
    Thanks for any tips.

    Probably each cover page is different too. I would probably just bite the bullet and do each individually. I would create the 2 cover pages in WORD or other word processor and print to cover.pdf. Then open a PDF and Pages>Insert Pages or the cover.pdf to the front of the open PDF and save as to the current PDF. Then repeat 299 times. Each time you would make the appropriate change to the DOC file and print a new cover.pdf file (you might want to turn off open in Acrobat for this processing in the printer properties to save time). Probably a good idea to keep a list of the files to check off what has been done (you can generate a list in DOS by Start>cmd, change the directory to your location [cd path], and do "dir >>list.txt". That will give you a list to use.). There may be an easier way, but by the time you get it figured out you might be done this way.

  • What is the best way of insertion using structured or binary type in oracle

    what is the best way of insertion using structured or binary type in oracle xml db 11g database

    SQL*Loader.

  • What is the best way to digitise some work manuals onto my iPad?

    What is the best way to digitise some work manuals onto my iPad? Thanks in advance.

    I honestly don't know if there's an app out there that can handle documents that large.
    Adobe has a free PDF app but i'm not sure if it allows authoring. And taking 200 separate scans and getting them put together into one book may require more resources than the iPad has.
    The ipads only have so much computing power and RAM, so if I were doing it I'd see if the place that scans them will sort them by chapters/topics of your manual.  So say each manual is 10 20 page sections (or however it breaks out)
    There are a lot of free pdf files on various sites (even the apple site has manuals for their stuff). Download some of those and try to open them on your iPad. See where the upper limit is of what your iPad will handle. Then use that as a guide to how you have the copy place break them up.

  • What is the easiest way to convert a jpeg into a watermark with CC 2014?

    What is the easiest way to convert a jpeg into a watermark with CC 2014?
    I signed a paper and uploaded the image to the computer as a jpeg to be turned into a watermark.  I'd done it before for a different kind of photography, but have not done it in so long that I cannot remember the steps nor can I find the tutorial video I had watched that taught me how to do it.
    Any help would be greatly appreciated

    Adding to what others have said, if you want to repeat the watermark across the image, it's relatively easy:
    As JJ said, you want to create an image with a transparent background. You can even use his script. Once you've done all that, click Image > Trim with the "transparent pixels" option and leave all the "trim away" options checked.
    Click Edit > Define Pattern to name the pattern.
    Open the image you want to apply the watermark to. Create a new blank layer. (ON EDIT: Select the blank layer.)
    Click Edit > Fill and use the Pattern option under Contents. Choose the pattern you made earlier. Click OK.
    At this point, you can leave it as is or use blending modes and layer opacity to taste. Example:

  • What is the best way to turn line art into a 3D image in Illustrator? Thanks for your help.

    What is the best way to turn line art into a 3D image in Illustrator? Thanks for your help.

    What version of Illustrator? What do you mean by "Line Art"? What do you mean by "3d image"? Post images showing your starting artwork and an example of what you are trying to achieve.
    If you have Illustrator 12 or higher you can extrude or lathe a simple group or path using Effects > 3D > [Pick one]. You must start with vector data, not a placed raster image. You are very limited in what you can do, and you cannot model multiple objects within one 3D world. Each object you extrude/revolve/rotate is its own world, with its own perspective and camera. You can also make any art into a Symbol, then map that symbol onto any 3D surface you create. The results are, at best, acceptable, and often total garbage.

  • What's the easiest way to embed a video into a specific part of an image map?

    What's the easiest way to embed a video into a specific part of an image map?
    Anybody help? Is there a way to do this in Dreamweaver?

    One way would be to create your image map first. Then, use the CSS property position to position the div containing the video player relative to the image map or absolute to the page (depending on how your website layout is).
    Then, use an event listener (javascript) to enable the div holding the video player to show only when the specific area on the image map is clicked.

  • Upgrading to SSD, what is the best way to clean install and transfer my files over?

    I am upgrading to an SSD and I would like to start clean by doing a fresh installation of Yosemite on the new drive. However, I still want all of my personal files from my current hard drive, like my music, music libraries, photos, and Home folder, transferred over to the new drive. What is the best way of doing this?
    I have Time Machine and a Time Capsule. Could I simply restore a Time Machine backup, or will that defeat the purpose of doing a clean install?
    Should I just back up the home folder and transfer the home folder onto an external drive, then drag the home folder to my new drive? Will that save my iTunes playlists and music?
    I don't need to transfer apps over so I'm not worried about that. Just my documents, files, pictures, music.

    How to replace or upgrade a drive in a laptop
    Step One: Repair the Hard Drive and Permissions
    Boot From An OS X Installer Disc
    1. Insert OS X Installer Disc into the optical drive.
      2. Restart the computer.
      3. Immediately after the chime press and hold down the "C" key.
      4. Release the key when the spinning gear below the dark gray Apple
          logo appears.
      5. Wait for installer to finish loading.
    Boot From a Recovery HD:
      1. Restart the computer.
      2. Immediately after the chime press and hold down the
          "COMMAND" and the "R" keys together.
      3. Release the keys when the Utilities Menu appears.
    After the installer loads select your language and click on the Continue button. When the menu bar appears select Disk Utility from the Installer menu (Utilities menu for Tiger, Leopard, Snow Leopard and later.)
    For Lion or later select Disk Utility from the Utilities Main Menu.
    After Disk Utility loads select your hard drive entry (mfgr.'s ID and drive size) from the the left side list.  In the Disk Utility status area you will see an entry for the S.M.A.R.T. status of the hard drive.  If it does not say "Verified" then the hard drive is failing or failed. (SMART status is not reported on external Firewire or USB drives.) If the drive is "Verified" then select your OS X volume from the list on the left (sub-entry below the drive entry,) click on the First Aid tab, then click on the Repair Disk button. If DU reports any errors that have been fixed, then re-run Repair Disk until no errors are reported. If no errors are reported click on the Repair Permissions button. Wait until the operation completes, then quit DU and return to the installer.
    If Disk Utility reports errors it cannot fix, then you will need Disk Warrior and/or Tech Tool Pro to repair the drive. If you don't have either of them or if neither of them can fix the drive, then you will need to reformat the drive and reinstall OS X.
    Step Two: Remove the old drive and install the new drive.  Place the old drive in an external USB enclosure.  You can buy one at OWC who is also a good vendor for drives.
    Step Three: Boot from the external drive.  Restart the computer and after the chime press and hold down the OPTION key until the boot manager appears.  Select the icon for the Recovery HD on the external drive, then click on the downward pointing arrow button.
    Step Four: New Hard Drive Preparation
      1. Open Disk Utility from the Utility Main Menu, then click on the Continue button.
      2. After Disk Utility loads select your new hard drive (this is the entry with the
          mfgr.'s ID and size) from the left side list. Note the SMART status of
          the drive in DU's status area.  If it does not say "Verified" then the drive
          is failing or has failed and will need replacing.  Otherwise, click on the
          Partition tab in the Disk Utility main window.
      3. Under the Volume Scheme heading set the number of partitions from
          the drop down menu to one. Set the format type to Mac OS Extended
          (Journaled.) Click on the Options button, set the partition scheme to
          GUID  then click on the OK button. Click on the Partition/Apply button and
          wait until the process has completed.
      4. Select the volume you just created (this is the sub-entry under the
          drive entry) from the left side list. Click on the Erase tab in the DU main
          window.
      5. Set the format type to Mac OS Extended (Journaled.) Click on the
          Options button, check the button for Zero Data and click on OK to
          return to the Erase window.
      6. Click on the Erase button. The format process can take up to several
          hours depending upon the drive size.
    Step Five: Clone the old drive to the new drive
      1. Select the destination volume from the left side list.
      2. Click on the Restore tab in the DU main window.
      3. Check the box labeled Erase destination.
      4. Select the destination volume from the left side list and drag it to the
          Destination entry field.
      5. Select the source volume from the left side list and drag it to the
          Source entry field.
      7. Double-check you got it right, then click on the Restore button.
    Destination means the new internal drive. Source means the old external drive.
    Step Six: Open the Startup Disk preferences and select the new internal volume.  Click on the Restart button.  You should boot from the new drive.  Eject the external drive and disconnect it from the computer.

  • What is the best way to put various songs into one album?

    I have been adding album information and album artwork within iTunes to take advantage of cover flow, but i have a lot of songs in my music library that are "stand alone" songs - it is the only song from that artist. I want to put all of these songs together in one album, so all of my miscellaneous rock songs will be put into a Rock Music album or file. I want to do this to eliminate all of the grey boxes within cover flow for all of these songs. When i give the files all the same album name (Rock Music) and album artist (Various Artists) it still does not put them all together within iTunes. It will do it for some, but not all.
    What is the best way to put all of these miscellaneous songs into the same album?

    Try marking all the tracks as part of a compilation. Click on the first track in your list, hold down the shift key and click on the last. Right click anywhere in the selection and choose Get Info, when you are asked if you want to edit multiple items say yes. Change compilation at the bottom of the window to Yes.

  • What is the best practice for inserting (unique) rows into a table containing key columns constraint where source may contain duplicate (already existing) rows?

    My final data table contains a two key columns unique key constraint.  I insert data into this table from a daily capture table (which also contains the two columns that make up the key in the final data table but are not constrained
    (not unique) in the daily capture table).  I don't want to insert rows from daily capture which already exists in final data table (based on the two key columns).  Currently, what I do is to select * into a #temp table from the join
    of daily capture and final data tables on these two key columns.  Then I delete the rows in the daily capture table which match the #temp table.  Then I insert the remaining rows from daily capture into the final data table. 
    Would it be possible to simplify this process by using an Instead Of trigger in the final table and just insert directly from the daily capture table?  How would this look?
    What is the best practice for inserting unique (new) rows and ignoring duplicate rows (rows that already exist in both the daily capture and final data tables) in my particular operation?
    Rich P

    Please follow basic Netiquette and post the DDL we need to answer this. Follow industry and ANSI/ISO standards in your data. You should follow ISO-11179 rules for naming data elements. You should follow ISO-8601 rules for displaying temporal data. We need
    to know the data types, keys and constraints on the table. Avoid dialect in favor of ANSI/ISO Standard SQL. And you need to read and download the PDF for: 
    https://www.simple-talk.com/books/sql-books/119-sql-code-smells/
    >> My final data table contains a two key columns unique key constraint. [unh? one two-column key or two one column keys? Sure wish you posted DDL] I insert data into this table from a daily capture table (which also contains the two columns that make
    up the key in the final data table but are not constrained (not unique) in the daily capture table). <<
    Then the "capture table" is not a table at all! Remember the fist day of your RDBMS class? A table has to have a key.  You need to fix this error. What ETL tool do you use? 
    >> I don't want to insert rows from daily capture which already exists in final data table (based on the two key columns). <<
    MERGE statement; Google it. And do not use temp tables. 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • I have some custom html5 tables, what's the best way to insert them in to Captivate 8?

    I have four html5 tables styled using css. They function perfectly in a browser - how do I get them into a Captivate slide?

    Hey, I think I’ve managed to crack it. So, I compressed my .html files to zip files. The HTML5 animation feature allows you to import zip files. So I imported the zip files into a Captivate slide and published the project to my desktop. On viewing it worked perfectly – maintaining all CSS. Perfect.
    Thanks for the help,
    Dan

  • What's the best way to define some values based on the URL?

    Let's say for example I want all my URLs for servlets to take the form:
    http://mysite.com/module/action?arguments
    What's the most scalable way to handle mapping the values in place of "module" and "action"? For example, I might have a "forum" module and have an action to "deleteThread", called like so:
    http://mysite.com/forum/deleteThread?id=321
    I know I can just parse it myself, but is there a better way to handle this via some settings in web.xml or similar? All my requests go through a Front Controller which needs to know which module and action have been requested so that it can run the appropriate action controller.
    Cheers,
    Chris

    At the risk of repeat-posting, I'll clarify. Say I create a file named routing.xml which defines some routes like this:
    <routing-config>
      <route>
        <name>Standard rule</name>
        <description>
          This route maps the first two parts in the path with the module and action
        </description>
        <url-pattern>/:module/:action.do</url-pattern>
      </route>
      <route>
        <name>Default Index</name>
        <description>
          Allows the module to be specified without the action for "Index" actions.
        </description>
        <url-pattern>/:module.do</url-pattern>
        <request-parameters>
          <parameter key="action" value="Index" />
        </request-parameters>
      </route>
      <route>
        <name>Homepage</name>
        <description>
          Loads the Home page
        </description>
        <url-pattern>/</url-pattern>
        <request-parameters>
          <parameter key="module" value="Home" />
          <parameter key="action" value="Index" />
        </request-parameters>
      </route>
    </routing-config>The bits like ":module" which be represented by the actual name of the module in the URL. Does anyone know if something like this already exists? :)
    I wrote this exact same thing in PHP5 just a few weeks ago but I really don't have the motivation to write it all over again in Java :P On a side-note, things like this usually come with helpers for turning unclean URIs into clean URIs.

Maybe you are looking for

  • OBYA - Customer and Vendor Clearing

    We all know that in OBYA you cane specify G/L accounts as well as customer and vendor accounts for clearing between company codes. Can any one explain what is the best way to follow and why? How do you clear these Open intercompany customers and vend

  • Multiple Playlists with Same Name

    What causes multiple Playlists with the same name or with the same name with a numerical suffix to appear?

  • Install CS5 with existing serial number using CS6 link in adobe

    I purchased a student version of CS5 so downloaded a trial and which I activated iwth my serial number. I need to reinstall it on my computer, but all the adobe links have changed the trial version to CS6. If I install CS6 trial, then activate with m

  • I can not find mcafeee siteadvisor in firefox 9?

    I recently updated to Firefox version 9. I do not see the McAfee SiteAdvisor on the screen. I have confirmed that I have it installed. Version is 3.4.1.122 but am not seeing any sign of it on screen or icons to show safe browsing. Can anyone advise?

  • Cassette to mac ,cont.

    After copy, cassette to 13 " Mac, I plan to again copy to an ipad or ipod, since you suggested quicktime ,will it also work . Great response .Bill