Writing files in Java - insert bytes

Hey.

I use to read/write files java.io.DataInputStream and java.io.DataOutputStream. However, I need to modify a file now, who needs me insert information in the middle of a previous file.

I see not all the methods in the DataOutputStream. Is there a way to "insert" in a middle of a file easily on bb, or I have to do custom - copy/replace/add things?

Best regards.

You could do it yourself, but it would be more difficult. You can buffer the data in the file yourself, but not necessarily knowing where to put buffer to or what buffer size could lead to reconsider reopening any watercourse. Depends on your situation.

Tags: BlackBerry Developers

Similar Questions

  • write 1 d digital table in a binary file and start a new line or insert a separator for each loop writing file

    Hello:

    I'm fighting with digital table of 1 d writeing in a binary file and start a new line or insert a separator for each loop writing file. So for each loop, it runs, LABVIEW code will collect a table 1 d with 253 pieces of a spectrometer. When I write these tables in the binay file and the following stack just after the previous table (I used MATLAB read binary file). However whenever if there is missing data point, the entire table is shifted. So I would save that table 1-d to N - D array and N is how many times the loop executes.

    I'm not very familiar with how write binary IO files works? Can anyone help figure this? I tried to use the file position, but this feature is only for writing string to Bodet. But I really want to write 1 d digital table in N - D array. How can I do that.

    Thanks in advance

    lawsberry_pi wrote:

    So, how can I not do the addition of a length at the beginning of each entry? Is it possible to do?

    On top of the binary file write is a Boolean entry called ' Prepend/chain on size table (T) '.  It is default to TRUE.  Set it to false.

    Also, be aware that Matlab like Little Endian in LabVIEW by default Big Endian.  If you probably set your "endianness" on writing binary file as well.

  • create multiple files from zip file using java and pl sql

    Hi all

    I wrote the java code in oracle database 11 g 2 below.

    DROP JAVA SOURCE SCOTT."CreateZip";
    
    CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED SCOTT."CreateZip" 
    as 
      import java.io.BufferedInputStream;
      import java.io.BufferedOutputStream;
      import java.io.File;
      import java.io.FileInputStream;
      import java.io.FileNotFoundException;
      import java.io.FileOutputStream;
      import java.io.IOException;
      import java.util.zip.Deflater;
      import java.util.zip.ZipEntry;
      import java.util.zip.ZipInputStream;
      import java.util.zip.ZipOutputStream;
      
      public class CreateZip 
      {  
        
        //public static final int BUFFER_SIZE = 4096;
        
        public static void Zip(String zipFileName, String zipEntries) throws IOException
        {
          
          //String strName = zipEntries;
          String[] srcFiles = new String[] {zipEntries};
          //String[] srcFiles = {zipEntries};
           
          try
          {
              byte[] buffer = new byte[4096];
              FileOutputStream fos = new FileOutputStream(zipFileName);
              ZipOutputStream zos = new ZipOutputStream(fos);        
          
              for (int i = 0; i < srcFiles.length; i++) 
              {
                  File entryFile = new File(srcFiles[i]);
                  FileInputStream fis = new FileInputStream(entryFile);
                  zos.putNextEntry(new ZipEntry(entryFile.getName()));
    
    
                  int length;
                  
                  while ((length = fis.read(buffer)) > 0)
                  {
                   zos.write(buffer, 0, length);
                  }
                  zos.closeEntry();
                  // close the InputStream
                  fis.close();
              }
              // close the ZipOutputStream
              zos.close();
          }
          catch (IOException e) 
          {
           e.printStackTrace();
          }
           
        }
        
        public static void UnZip(String zipFilePath, String destDirectory) throws IOException 
        {
         
         try
          {
           byte[] buffer = new byte[4096];   
           //create output directory is not exists
            File folder = new File(destDirectory);
            if(!folder.exists())
            {
                folder.mkdir();
            }
            //get the zip file content
            ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFilePath));
            //get the zipped file list entry
            ZipEntry ze = zis.getNextEntry();
            
            while(ze!=null)
            {
              String fileName = ze.getName();
              File newFile = new File(destDirectory + File.separator + fileName);
              //create all non exists folders
              //else you will hit FileNotFoundException for compressed folder
              new File(newFile.getParent()).mkdirs();
              FileOutputStream fos = new FileOutputStream(newFile);
              int len;
              while ((len = zis.read(buffer)) > 0)
                 {
                  fos.write(buffer, 0, len);
                 }
                 
              fos.close();   
              ze = zis.getNextEntry();
              
            }
            zis.closeEntry();
            zis.close();
          }
          catch (IOException e) 
          {
           e.printStackTrace();
          }
          
        }
        
        
      }
    /
    

    and the pl/sql wrapper is lower.

    CREATE OR REPLACE PACKAGE SCOTT.CreateZip AS
    PROCEDURE UnZip(Param1 VARCHAR2, Param2 VARCHAR2) 
    AS
      LANGUAGE java 
        NAME 'CreateZip.UnZip(java.lang.String, java.lang.String)';
    
    
    PROCEDURE Zip(Param1 VARCHAR2, Param2 VARCHAR2) 
    AS
      LANGUAGE java 
        NAME 'CreateZip.Zip(java.lang.String, java.lang.String)';
    end;
    /
    

    but my problem is to unzip code works file while the Zip function does not work.

    I passing the path with file name as this to create the table in java in the Zip function

    Zip('d:\EXCEL_ORACLE_DIR\Test.zip','d:\EXCEL_ORACLE_DIR\abc.txt,D:\EXCEL_ORACLE_DIR\abc.docx').

    creates the zip file with the size of zero byte, where is the problem.

    The problem is in line 26 because you split an array of String [] zipEntries...

    Try this

    String [] srcFiles = zipEntries.split(",");

    You exception, but you don't know in plsql procedure...

    Try to change your java method...

  • ORA-29285: error writing file

    Hi, I'm trying to clear a table in a flat file, & provided the stored procedure using my Tom Kyte @ https://asktom.oracle.com/pls/asktom/f?p=100:11:0:NO:P11_QUESTION_ID:88212348059.

    It worked well at first, but now I always get the following error message:

    ERROR on line 1:

    ORA-29285: error writing file

    ORA-06512: at "OFSA_ATOMIC. DUMP_TAB_TO_CSV", line 45

    ORA-06512: at line 1

    The search for this error ORA out Virgin on MOS.

    Any ideas how to solve this problem?

    I already checked for space on the file system and there is lots of space available.

    Also, the file is created with a size of 0 bytes before the procedure was abandoned.

    Thank you

    -CV

    Hello

    trying to figure out what has changed since it worked. Length of the line would be greater than 1024 default that uses Tom proc?

    http://docs.Oracle.com/CD/E11882_01/AppDev.112/e40758/u_file.htm#ARPLS70900

    The FOPEN max_linesize parameter must be a number in the range 1 to 32 767. If not specified, Oracle provides a default value of 1024.

  • Exception is coming when writing files on FTP through business services

    Hello

    Exception is coming when writing files on FTP through business services

    I write file on the FTP of Business Service Oracle Service Bus. The file was written successfully, but in the following exception logs is coming. Is there a solution to remove this exception. or why when you rename the file there.

    < 28 August 2014 9:49:29 AM GMT + 05:00 > < error > < WliSbTransports > < BEA-381105 > < error occurred for the service endpoint: com.bea.wli.sb.transports.TransportException: file could not be renamed to: TESTFILE/TEST.a to: TESTFILE/TEST

    com.bea.wli.sb.transports.TransportException: file could not be renamed to: TESTFILE/TEST.a to: TESTFILE/TEST

    at com.bea.wli.sb.transports.ftp.connector.FTPTransportProvider.sendMessage(FTPTransportProvider.java:422)

    at com.bea.wli.sb.transports.ftp.connector.FTPTransportProvider.sendMessageAsync(FTPTransportProvider.java:306)

    at sun.reflect.GeneratedMethodAccessor672.invoke (unknown Source)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

    at java.lang.reflect.Method.invoke(Method.java:597)

    Truncated. check the log file full stacktrace

    Caused by: java.io.IOException: file could not be renamed to: TESTFILE/TEST.a to: TESTFILE/TEST

    at com.bea.wli.sb.transports.ftp.resource.FTPResource.renameToUniqueFilePath(FTPResource.java:1962)

    at com.bea.wli.sb.transports.ftp.connector.FTPTransportProvider.sendMessage(FTPTransportProvider.java:415)

    at com.bea.wli.sb.transports.ftp.connector.FTPTransportProvider.sendMessageAsync(FTPTransportProvider.java:306)

    at sun.reflect.GeneratedMethodAccessor672.invoke (unknown Source)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

    Truncated. check the log file full stacktrace

    Kind regards

    Junaid Ahmed

    Yes, read/write access is available. but when I send the name of the file TEST. A there is no Exception. OSB is 11.1.1.6.0 and I do FTP OSB business for iSeries. I don't know what will be the reason.

  • An animated (gif) file can be inserted into an email, or must it be attached?

    An animated gif file can be inserted into an e-mail? It's something that worked when I was using Outlook 2003, but does not work in Outlook 2010. Thunderbird allows a fully animated gif file in an email, or only as an attachment >

    It is animated by the recipient; Save as draft or see envoys.

  • Ribbon verses... file, editing, display, insert, tools, table, window, and help

    In windows, I have the tape but have not... the file edit, view, insert, tools, table, window, and help (with drop downs) as it did in the older version.  If it's hidden?

    hj714,
    You must search Desktop and personalization forum and post there is not to find and answer.  Be sure to include your version of Windows and what programs you encounter this problem with. Mike - Engineer Support Microsoft Answers
    Visit our Microsoft answers feedback Forum and let us know what you think.

  • can anyone help, my windows media player says is writing files on cd/dvd, but it comes out as white

    Hi people says its writing files to the disc, but when I put back it in the laptop or another player yet to come sound like a blank disc, tried a lot of different cd/dvd discs

    Hello

    ·        You did changes to the computer before the show?

    ·        You receive an error message or code?

    Method 1: I suggest you follow the instructions in the link and check if this may help:

    http://Windows.Microsoft.com/en-us/Windows-Vista/burn-a-CD-or-DVD-in-Windows-Media-Player-frequently-asked-questions

    Method 2: You can also try to change the settings for burning a CD/DVD and check if it helps:

    http://Windows.Microsoft.com/en-us/Windows-Vista/change-settings-for-burning-a-CD-or-DVD-in-Windows-Media-Player

    Note: reduce speed before burning the data and then check if it helps.

  • I installed the download tool usb/dvd windows 7, but after you have selected the iso file when I insert the USB stick and refrecing, it does show that "no usb drive compatible' what is the problem with my USB

    I installed the download tool usb/dvd windows 7, but after you have selected the iso file when I insert the USB stick and refrecing, it does show that "no usb drive compatible' what is the problem with my USB

    I have sandisk cruzer blade USB key

    Hi Rohit,

    Thanks for posting your query in Microsoft Community Forum. I understand that your USB drive is having problems of compatibility with your computer, but I would like to learn more about the issue in order to provide you with better assistance.

    1. You did it any significant hardware or change software on the computer before this problem?
    2. When do you get exactly the error message?
    3. Have you tried to connect to any other computer on this flash drives?
    4. Your USB key works on other computers or have you tried to connect to different USB ports on this computer?
    5. Is the pen drive getting detected in the case or you are able to access the drive folder in the window of the computer ?

    The question may arise if the currently loaded USB driver has become unstable or damaged, or if your PC requires an update for problems that could conflict with a device USB and Windows. This can also occur if your USB controllers may have become unstable or corrupt. So, I would suggest trying the following steps and check if the problem persists.

    Method 1:

    Please try the fixit (s) provided below which will help you solve common problems associated with devices and USB ports.

    If method 1 does not work, try Method 2.

    Method 2:

    Remove and reinstall all USB controllers.

    1. Open Manager devices by clicking the Start button, click Control Panel, click system and security, and then, under System, clicking Device Manager. If you are prompted for an administrator password or a confirmation, type the password or provide confirmation.
    2. In the list of the categories of equipment, locate and expand Bus USB controllers.
    3. Right-click every device under the Bus USB controllers node and then click Uninstall to remove them one at a time.
    4. Restart the computer and let the USB controllers get reinstalled.

    Plug in the removable USB device and test to make sure that the problem is solved.

    If the problem persists, go to method 3.

    Method 3:

    This method will install the latest drivers from device to your USB device.

    1. Click the Start button, type Windows Update in the search box, and then click Windows Update in the results pane.
    2. Click find updates. When the scan finished, click optional review updates.
    3. Click the check box next to the update, and then click install updates.
    4. If you are prompted, read the license agreement, then click I agree.
    5. Follow the instructions on the screen to download and install updates.
    6. If you are prompted, restart your computer.

    More information: Update a hardware driver that is not working properly

    Hope this information is useful. If the problem still persists, please post back for further assistance, we will be happy to help you.

  • I changed my default program to open the .jar files in Java...

    I changed my default program to open the .jar files in Java... but now they all open as windows of command for half a second before disappearing (Windows 8 BTW) so how can I reset it to open it but it feels like it?

    Try the system restore to undo your mistake.

    How to repair the operating system and how to restore the configuration of the operating system to an earlier point in time in Windows Vista (7 or 8).
    http://support.Microsoft.com/kb/936212/#appliesTo

    See, control Panel\All Control Panel Items\Recovery\ Open System Restore

    Take a look at the control Panel\All Control Panel Items\Default Programs\Set Associations and set the correct program for a .jar file.

    Java uninstallation and reinstallation of Java could fix.

    Windows 7 - how [closed] open JAR files

    http://StackOverflow.com/questions/11617239/Windows-7-How-to-open-jar-files

    http://www.Google.com.au/search?q=what+program+or+process+opens+.jar&SourceID=IE7&RLS=com.Microsoft:-to THE: IE-address & ie = & oe = & gws_rd = cr & ei = iyFPUtjtOsvtiAel6oHICQ

  • Creating files EOImpl.java varies with jDev 12.1.3 version?

    Hello gurus of the ADF.

    Referring below file image, my question concerns the EOImpl.java file created by jDeveloper 11 g(Left pane)-12 c (right pane).

    It is extract from from OrderItemEOImpl.java table ORDER_ITEMS file of a FOD (Fusion order Demo) schema.

    Description of the table for some attributes-

    PRODUCT_ID NOT NULL NUMBER (15)

    QUANTITY NOT NULL NUMBER (6)

    UNIT_PRICE NOT NULL NUMBER (8.2)

    Now the question is the EOImpl.java file created by jDev 11g (left side) is to have class oracle.jbo.domain.Number for Number (15), NUMBER (6) and NUMBER (8.2) respectively

    but

    File EOImpl.java created by jDev 12.1.3 (right) is to have long, Integer, BigDecimal to Number (15), NUMBER (6) and NUMBER (8.2) respectively

    ..

    So in jDev 12 c oracle.jbo.domain.Number was obsolete or is there any other reason for this difference?

    Please let me know if any way I can generate an EOImpl.java file via jDev - 12 c oracle.jbo.domain.Number containing?

    Capture.JPG

    JDev 12 c use a different type mapping, then JDve 11 g, the shift was designed to use the java types rather than the Oracle domain types.

    When you create a model project you can choose the old Oracle type card, however there should be no reason to do so.

    And this decision cannot be reversed, so you have to re-create the projects of existing models.

    Timo

  • I currently store my pictures on and an external hard drive.  Lightroom 6 was not able to find the picture momentarily files.  I inserted an external Flash DRIVE after removing the hard drive and the computer renamed the stick with the same drive letter t

    Redesign existing external hard disks and still 6 Lightroom able to find existing photos.

    I currently store my pictures on and an external hard drive.  Lightroom 6 was not able to find the picture momentarily files.  I inserted an external Flash DRIVE after removing the hard drive and the computer renamed the stick with the same drive letter that has been designated by Lightroom to store my photos.  I could go into my Windows 10 and reset the player to the letter that Lightroom has given at the beginning of the external hard drive.   However, I know this can happen again, if I connect any stick USD or another device, while the external hard drive is not connected to my laptop.   I found the information that I can do the new designation of the final drive by choosing a letter it is 1/2 way or higher in the alphabet.   I would like to turn an external hard drive on a strong letter, warns we hope this previous problem.   My question is, if I already have a lot of pictures on this external hardrive with the designation of the current drive, how it becomes a higher letter and have 6 Lightroom recognizes files, now under the new designation of drive letter without having to go to each photo individually and manually force Lightroom 6 find each photo.  It would take more time than I'd like to lose.  Is there a way to get just 6 Lightroom to recognize the new disk designation has changed and is able to find all of the existing files?

    I have read the ADOBE LightRoom 6 manual and seem not to be able to find anything on how to do it.

    Any help would be welcome.

    Thank you!

    So in Windows, you can select a drive like q letter (or any other letter you want only towards the end of the alphabet)

    Then in Lightroom, you can reconnect to the photos on q: the following instructions (see specifically 4 Figure and related text)

    Adobe Lightroom - find moved or missing folders and files

  • Edge animate Composition does not exist in the inert menu to put the file Edge OAM (insert &gt; media &gt; Ed)

    I joined Adobe Cloud. Edge animate Composition does not exist in the inert menu to put the file Edge OAM (insert > media > edge animate Composition). Why?

    Post your question in the forum Adobe Edge animate here http://forums.adobe.com/community/edge_animate. They will be able to help you.

  • How To Read RTF file in JAVA?  Using iText?

    How To Read RTF file in JAVA?  Using iText?...

    import java. IO;

    com.lowagie.text import. *;
    com.lowagie.text.rtf import. *;

    public class RTF3 {}
    Public Shared Sub main (String [] args) {}

    System.out.println ("this example produces a RTF Sample.rtf file name");

    Create the Document object
    The myDoc document = new Document();

    try {}

    Create writer to listen to a document object
    and directs the RTF stream to the Sample.rtf file
    RtfWriter2.getInstance (myDoc, new FileOutputStream ("Sample.rtf"));

    Open the document object
    myDoc.open ();

    Create a paragraph
    Point p = new Paragraph();
    p.Add ("Helloworld in Rtf file... amazing isn't");

    Add a paragraph to the document object
    myDoc.add (p);

    }
    catch (Exception e) {}
    System.out.println (e);
    }
    close the document
    myDoc.close ();
    }
    }
    Exception in thread "main" java.lang.NoSuchMethodError: com.lowagie.text.Rectangle.width (F)
    at com.lowagie.text.rtf.document.RtfPageSetting.rectEquals(RtfPageSetting.java:433)
    at com.lowagie.text.rtf.document.RtfPageSetting.guessFormat(RtfPageSetting.java:362)
    at com.lowagie.text.rtf.document.RtfPageSetting.setPageSize(RtfPageSetting.java:341)
    at com.lowagie.text.rtf.RtfWriter2.setPageSize(RtfWriter2.java:248)
    at com.lowagie.text.Document.open (unknown Source)
    to the view. RTF3.main (RTF3. Java:23)

    Can you help me?

    import com.lowagie.text.Document;
    import com.lowagie.text.rtf.parser.RtfParser;
    import java.io.FileInputStream;

    String Fichierentree = "sample.rtf."
    Document document = new Document();
    document. Open();
    RtfParser parser = new RtfParser (null);
    parser.convertRtfDocument (new FileInputStream (inputFile), document);

  • Using InDesign CS3, cannot "file &gt; place" to insert anything

    I use InDesign CS3 on a Windows XP computer. When I go to file > place to insert anything (image, PDF, text, whatever), the dialog box import a VERY QUICK flashing (if fast I see nothing but the shape of the box) and crashes then InDesign. Also having the same problem with file > open. All the other options under the file menu seem to work well.

    I tried scrapping the preferences file, but that did not help. I have a 15 page PDF that I need to get into InDesign immediately and do not understand anything.

    Help!

    Thank you.

    Veronica Scrimshaw

    Paste is NOT a good option for anything other than the simple vector art you would like to keep editable within the code.

    Just because you've seen the average flash dialog box doen't it did not move off the screen or behind something else. Try to hit the ESC key and see if ID wake. Which would indicate that the dialogue was still active and accepted the command "Cancel". If it works, the problem becomes how to find dialog box.

    When the dialog box disappears try pressing Alt + space, then M, bar which should activate the arrow keys to move a dilog which is at the edge of the screen. Press the arrow keys 20 or 30 times in one direction and then twice more that the other way to see if you can find the dialog box disable one edge or the other of the screen - it is just try it and see approach. Opeing a dialog box in Photoshop and resize, he was also known to cure this kind of behavior from time to time.

    And if you have multiple monitors, try to run at native resolution, if they are flat screens.

Maybe you are looking for