Inserting a newline using RandomAccessFiles

Hi,
Im trying to insert a new line halfway throug a text document using randomAccessFile but java wont allow me to use
RandomAccessFile fw = new RandomAccessFile( FileName, "rw" );
fw.seek(Pos[0]);
fw.write(System.getProperty("line.seperator"));it also wont add a new line when I use fw.writeUTF("\n");Please help Me

Bardy wrote:
Hi,
Im trying to insert a new line halfway throug a text document using randomAccessFile but java wont allow me to...It's not just Java. Your operating system stores a file as a contiguous set of bytes on a disk. There is no way, using Java or any other language, to just insert something in the middle of that.
To insert something in the middle of a text document, here's what you have to do:
1. Read the data from the original file before the insertion point and write it out to a second file.
2. Write the data you want to insert out to the second file.
3. Read the rest of the data from the original file and write it out to the second file.
4. Close all your files.
5. Delete the original file.
6. Rename the second file to have the original file's name.

Similar Messages

  • I created a Pages document inserting 2 columns using 1) Inspector 2) Layout 3) columns.  How do I decrease the height of the column.  Have tried to use cursor and drag down the top border, but that does not reset the top border.

    I created a Pages document inserting 2 columns using 1) Inspector 2) Layout 3) columns.  How do I decrease the height of the column.  Have tried to use the cursor and drag down the top border, but that does not reset/decrease the top border.

    Set your columns back to one for the moment. In layout mode, insert a Text box. Place it in the upper left corner of your document, and drag down and right to the size of the container for your two columns. Click inside the Text Box, and now bump up your columns to 2. Your two columns are now contained in this resizable Text Box.

  • Insert Multiple records using Database adapter with Stored procedure func

    Hi All,
    I want to insert multiple records on a database using a stored procedure. I wanted to insert those records using a Database Adapter and the Database adapter should be invoked by a Mediator.
    Can somebody suggest me with ideas whether it can be acheived with OOB capabtilities in SOA suite or not?
    Thanks for your help in advance.
    Thanks,
    Shiv

    The use case you want to achieve is feature supported by the DBAdapter and it is possible to invoke the same from mediator.
    Please have a look at the oracle documentation and you should be able to get the necessary information.
    The below links should help you as well:
    http://download.oracle.com/docs/cd/E15523_01/integration.1111/e10231/adptr_db.htm
    http://blogs.oracle.com/ajaysharma/2011/03/using_file_adapter_database_adapter_and_mediator_component_in_soa_11g.html
    There are some video tutorials as well :)
    http://www.youtube.com/watch?v=dFldS-fDx70 This should also help
    Thanks,
    Patrick

  • Can I Trick Presenter to allow me to Insert Video By Using Coding ?

    I am currently evaluating Abobe Presenter 7.0.7.   It has the tools to allow me to make by presentations, but the major limitation for me is the fact that I must manually insert video by using the "Adobe Presenter" toolbar.   I need a means of automating the process of insert the video into the power point slides without doing it by hand using the "Adobe Presenter" toolbar.   I am currently using flv files.  Can anyone help ??
    This is what I have noticed so far:
    1)     Inorder to publish the presentation, there is a folder created with the same name as your power point presentation.  Within that folder is a folder called "Assets".   Inside this folder you will file various flv files names like "v20110123_031_272_1_24357".   The original flv filename is "v20110123_031.flv".    I believe this is where the video file is placed when I use the "Adobe Presenter" insert video tool.
    2)     I also noticed that the power point slide has an object called "Shockwave Flash Object", and when I select this and display the "Properties" window, I see the following that seems important:  a)  Embed Movie = True, b)  Loop = False, and c)  MovieData = file path of video
    3)     I used the "more controls" toolbar that is part of power point and selected "Shockwave Flash Object" and scaled in a box on one of my slides.   I changed all of the properties to what I indicated in #2 above.  The "MovieData" file path was change to the correct path I the "Adobe Presenter" insert video did, but I change the flv file name and duration to the correct side.   I made a test case and insert the video in another presentation and copied it, but I made sure the pathname is correct for my test.
    3)     I am able to publish without any errors, the the inserted flv does play.   I assure its not working correctly.
    Does anyone know what I can try to get something like this to work (without using the "Adobe Presenter" invert video) because I am abvle to write MS VBA Code to generate everything else.
    All my power point slides are generated by using MS VBA code completely because I have many of these to do each week for over 18 weeks.
    I would appreciate any help or suggestions of other tools that I can use. 
    I believe Captivate also has this issue where I have to do this manually.
    Thank You,
    G

    I don't really know too much about AutoIt Tool.   This is what I tried:
    1)     I used MS Access VBA Code to open my power point slides and use the SendKeys to open various menu in the power point slides.   I do see the menu called "Adobe Presenter".
    So I tried using the SendKeys "%{P}", True    which sends out the command Alt+P which is suppose to open the "Adobe Presenter" drop down menu.   It didn't do that but open the "View" Menu and select the "Header and Footer" menu.
    So I tried using the SendKeys "%{I}", True   which sends out the command Alt+I which is suppose to open the "Insert" menu drop down and it works.   For some reason it didn't work for the "Adobe Presenter" menu.
    2)     When I just open power point and type Alt+P, it does open the "Adobe Presenter" drop down menu.  
    Any idea ??     Do you think the AutoIt may work better for me ???
    Thank You,
    G

  • Delete the specified character in a text file using RandomAccessFile

    Hi All,
    I have an invalid XML file which contains Return characters at the end of each line. I need to delete these return characters so the file becomes valid.
    Does anybody have any idea how this could be done using RandomAccessFile?
    I found joop_eggen's posting in this forum, modified it just a little and wanted to use it, but since the replacement character is "" (blank) it does not do what I need to.
    The XML file looks like this:
    <?xml version="1.0"?>
    <EPMSObject>
    <EPMSRecord><facilityname>KT0</facilityname><date_time>2007-06-01T00:00:00</date_time><devicetype>RPP</devicetype><devicename>RPP1A1_001.BCMF</devicename><meter>BCMF</meter><ckt_01_current>4.136000000000000e+000</ckt_01_current><ckt_02_current>0.000000000000000e+000</ckt_02_current><ckt_03_current>5.521000000000000e+000</ckt_03_current><ckt_04_current>0.000000000000000e+000</ckt_04_current><ckt_05_current>5.880000000000000e+000</ckt_05_current><ckt_06_current>0.000000000000000e+000</ckt_06_current><ckt_07_current>4.086000000000000e+000</ckt_07_current><ckt_08_current>0.000000000000000e+000</ckt_08_current><ckt_09_current>4.994000000000000e+000</ckt_09_current><ckt_10_current>0.000000000000000e+000</ckt_10_current><ckt_11_current>4.374000000000000e+000</ckt_11_current><ckt_12_current>0.000000000000000e+000</ckt_12_current><ckt_13_current>4.314000000000000e+000</ckt_13_current><ckt_14_current>0.000000000000000e+000</ckt_14_current><ckt_15_current>4.112000000000000e+000</ckt_15_current><ckt_16_current>0.000000000000000e+000</ckt_16_current><ckt_17_current>4.287000000000000e+000</ckt_17_current><ckt_18_current>0.000000000000000e+000</ckt_18_current><ckt_19_current>4.254000000000000e+000</ckt_19_current><ckt_20_current>0.000000000000000e+000</ckt_20_current><ckt_21_current>3.970000000000000e+000</ckt_21_current><ckt_22_current>0.000000000000000e+000</ckt_22_current><ckt_23_current>5.640000000000000e+000</ckt_23_current><ckt_24_current>0.000000000000000e+000</ckt_24_current><ckt_25_current>7.123000000000000e+000</ckt_25_current><ckt_26_current>0.000000000000000e+000</ckt_26_current><ckt_27_current>5.118000000000000e+000</ckt_27_current><ckt_28_current>0.000000000000000e+000</ckt_28_current><ckt_29_current>6.094000000000000e+000</ckt_29_current><ckt_30_current>0.000000000000000e+000</ckt_30_current><ckt_31_current>0.000000000000000e+000</ckt_31_current><ckt_32_current>0.000000000000000e+000</ckt_32_current><ckt_33_current>0.000000000000000e+000</ckt_33_current><ckt_34_current>0.000000000000000e+000</ckt_
    34_current><ckt_35_current>0.000000000000000e+000</ckt_35_current><ckt_36_current>0.000000000000000e+000</ckt_36_current><ckt_37_current>0.000000000000000e+000</ckt_37_current><ckt_38_current>0.000000000000000e+000</ckt_38_current><ckt_39_current>0.000000000000000e+000</ckt_39_current><ckt_40_current>0.000000000000000e+000</ckt_40_current><ckt_41_current>0.000000000000000e+000</ckt_41_current><ckt_42_current>0.000000000000000e+000</ckt_42_current></EPMSRecord>
    </EPMSObject>
    Here is joop_eggen's code:
    import java.io.*;
    import java.nio.*;
    import java.nio.channels.*;
    public class Patch {
      private static byte[] sought;
      private static byte[] replacement;
      private static boolean matches(MappedByteBuffer bb, int pos) {
        for (int j = 0; j < sought.length; ++j)
          if (sought[j] != bb.get(pos + j))
            return false;
        return true;
      private static void replace(MappedByteBuffer bb, int pos) {
        for (int j = 0; j < sought.length; ++j)
          byte b = (j < replacement.length)? replacement[j] : (byte)' ';
          bb.put(pos + j, b);
      private static void searchAndReplace(MappedByteBuffer bb, int sz) {
        int replacementsCount = 0;
        for (int pos = 0; pos <= sz - sought.length; ++pos)
          if (matches(bb, pos)) {
            replace(bb, pos);
            pos += sought.length - 1;
            ++replacementsCount;
        System.out.println("" + replacementsCount + " replacements done.");
        // Search for occurrences of the input pattern in the given file
        private static void patch(File f) throws IOException {
        // Open the file and then get a channel from the stream
        RandomAccessFile raf = new RandomAccessFile(f, "rw"); // "rws", "rwd"
        FileChannel fc = raf.getChannel();
        // Get the file's size and then map it into memory
        int sz = (int)fc.size();
        MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_WRITE, 0, sz);
        searchAndReplace(bb, sz);
        bb.force(); // Write back to file, like "flush()"
        // Close the channel and the stream
        raf.close();
        public static void main(String[] args) {
        String E_O_L;
        E_O_L = System.getProperty( "line.separator" );
        if (args.length == 0)
          args = new String[] { E_O_L, "", "C:\\GTI\\EPMSRecords.xml" };
        if (args.length < 3) {
          System.err.println("Usage: java Patch sought replacement file...");
          return;
        sought = args[0].getBytes();
        replacement = args[1].getBytes();
        //if (sought.length != replacement.length) {
          // Better build-in some support for padding with blanks.
          //System.err.println("Usage: sought (" + args[0] + ") and replacement (" + args[1] + ") must have same length");
          //return;
        for (int i = 2; i < args.length; i++) {
          File f = new File(args);
    try {
    patch(f);
    } catch (IOException x) {
    System.err.println(f + ": " + x);
    Thank you,
    Sinan Topuz

    Thank you all.
    Here is what I have right now and it works very well. It takes a couple of seconds to generate the second file and that satisfies me. I took the code sabre150 posted in this forum and changed it just a little bit, so thanks to him.
    I hope this helps someone.
    Sinan
    import java.io.*;
    public class SearchReplace{
        public static void main(String[] args){
            if(null == args || args.length < 2) {
               System.err.println("\nUsage: java <inputFileFullPath> <OutputFileFullPath> \nExample: java C:\\GTI\\Epmsrecord.xml C:\\GTI\\EpmsrecordNEW.xml");
               System.exit(1);
            Reader reader = null;
            Writer writer = null;
            try{
                char cr;
                char lf;
                char sp;
                int  indx;
                cr = '\r';
                lf = '\n';
                sp = ' ';
                indx = 0;
                reader = new FileReader(args[0]);
                writer = new FileWriter(args[1]);
                for (int ch = ' '; (ch = reader.read()) != -1;){
                    indx++;
                    if ( indx > 15 ) {      // Skip the first space character in <?xml version="1.0"?> otherwise the file becomes invaild!
                        if (ch != cr && ch != lf ) {
                            writer.write(ch);
                    }else{
                        writer.write(ch);
                System.out.println("\nFile " + args[1] + " has been successfully created.");
            }catch(FileNotFoundException fnfe){
                System.out.println("\nError : File " + args[0] + " not found. Please make sure it exists and you have rights to access to it.");
            }catch (IOException e) {
                System.err.println("Caught IOException: " +  e.getMessage());
            }finally {
                try {
                    if ( reader!=null ) {
                        reader.close();
                    if ( writer!=null ) {
                        writer.close();
                }catch (IOException e){
                    System.err.println("I/O error occured while trying to close the files.");
    }

  • Inserting multiple rows using a single Insert statement without using dual

    Hi all,
    i am trying to insert multiple rows using a single insert statement like the below one.
    The below one works fine..
    But is there any other change that can be done in the below one without using dual...
    insert all
    into ps_hd_samp (num1,num2) values (1,1)
    into ps_hd_samp (num1,num2) values (2,2)
    into ps_hd_samp (num1,num2) values (3,3)
    select 1 from dual;

    NiranjanSe wrote:
    Hi all,
    i am trying to insert multiple rows using a single insert statement like the below one.
    The below one works fine..
    But is there any other change that can be done in the below one without using dual...
    insert all
    into ps_hd_samp (num1,num2) values (1,1)
    into ps_hd_samp (num1,num2) values (2,2)
    into ps_hd_samp (num1,num2) values (3,3)
    select 1 from dual;
    SQL> create table ps_hd_samp (num1 number,num2 number);
    Table created.
    SQL> insert all
      2  into ps_hd_samp (num1,num2) values (1,1)
      3  into ps_hd_samp (num1,num2) values (2,2)
      4  into ps_hd_samp (num1,num2) values (3,3)
      5  select count(*)
      6  from ps_hd_samp;
    3 rows created.
    SQL> select * from ps_hd_samp;
          NUM1       NUM2
             1          1
             2          2
             3          3

  • Using RandomAccessFile with 9iAS

    I have a question about reading (and writing) ASCII files with fixed-length records in an application that will run under OC4J. (FWIW, the application uses no EJBs.)
    Since the J2EE spec forbids standard file i/o, it would seem that using RandomAccessFile is not an option.
    Purchasing a JDBC driver for text files is not an option for our project, either.
    Does 9iAS provide any other options, besides ignoring the J2EE spec?
    TIA,
    Al Margheim

    Al -- I think it's only the EJB spec which forbids the use of IO and threading operations. As I understand it, from a servlet you should be OK to write to the filesystem. Of course, you'll need to do the work to make sure your app is threadsafe and IO safe (ie two concurrent requests can't try and write to the same file).
    cheers
    -steve-

  • Inserting Chinese character using sqlplus

    I am not able to insert Chinese character using sqlplus .
    Am getting disconnected when trying to insert.
    with no error
    message coming
    is disconnected form oracle enterpise 10.2.0.2.0 with .. mining..
    Please help.

    sql is simple insert statement
    insert into t5(txt) values ('中中 中 中 中 中 中 中 中 中 ');
    os is AIX
    I wonder when i using sql developer I am able to insert.
    regarding environmental variable , I am not setting any variable regarding NLS.
    I simply connect sqlplus username/password
    when I execute following statement
    sqlplus disconnect without giving any error.
    question is why sql developer is able able to insert and sqlplus not
    Thanks for reply

  • How to insert the data using matrix

    Hi
      All how to insert the data using matrix feild
      plz help me
       thanks
        Loy

    Hi Loy,
    The best way to fill an entire matrix is to use a DBDatasource, here is some sample code:
    Dim oForm As SAPbouiCOM.Form
    oForm = SBO_App.Forms.Item("YourFormTypeID")
            '1. Add a DBDataSource to the form
            oForm.DataSources.DBDataSources.Add("OUSR")
            Dim oColumnDBS As SAPbouiCOM.Column
            Dim oColumnUDS As SAPbouiCOM.Column
            Dim i As Integer
            Dim GenEdt As SAPbouiCOM.EditText
            Dim oMatrix As SAPbouiCOM.Matrix
            Dim oColumns As SAPbouiCOM.Columns
            Dim oDBDataSource As SAPbouiCOM.DBDataSource
            oMatrix = oForm.Items.Item("7").Specific
            oColumns = oMatrix.Columns
            '2. DBDataSource: Binding a field / alias of the table to a column
            oColumnDBS = oColumns.Item("V_1")
            oColumnDBS.DataBind.SetBound(True, "OUSR", "U_NAME")
            '3. getting the data sources bound to the form
            oDBDataSource = oForm.DataSources.DBDataSources.Item("OUSR")
            oMatrix.Clear()
            ' Querying the DB Data source
            oDBDataSource.Query()
            ' Adding the data to the matrix
            oMatrix.LoadFromDataSource()
    When you want to fill a specific field use :
    GenEdt = oMatrix.Columns.Item("V_2").Cells.Item(1).Specific
                    GenEdt.String = "Hello"

  • Unable to generate insert stmt scripts using sql developer

    We are not able to generate INSERT statement script using SQL Developer. In the INSERT script system is inserting some spaces due to carriage return which we cannot reviewed individually.

    DELETE FROM IM_INSTANCE_EXT_VAL_FRM
    WHERE IEVF_TRG_FLD_NAME = 'PRAI_NUM_03'
    AND IEVF_INST_CODE = 'APV-QQ-03'
    AND IEVF_BLK_NAME = 'PGIT_POL_RISK_ADDL_INFO_01';
    -- INSERTING into IM_INSTANCE_EXT_VAL_FRM
    Insert into IM_INSTANCE_EXT_VAL_FRM (IEVF_SYS_ID,IEVF_INST_CODE,IEVF_PROG_CODE,IEVF_BLK_NAME,IEVF_TRG_FLD_NAME,IEVF_ACT_FLDS,IEVF_ACTION,IEVF_PROC,IEVF_SRNO,IEVF_ERR_NO,IEVF_ERR_YN,IEVF_APP_CODE,IEVF_REMARKS,IEVF_UPD_UID,IEVF_UPD_DT,IEVF_CR_UID,IEVF_CR_DT,IEVF_TRG_NAME,IEVF_CLEAR_FLD_YN,IEVF_VALIDATE_YN) values (IEVF_SYS_ID.NEXTVAL,'APV-QQ-03','PGIT6_03','PGIT_POL_RISK_ADDL_INFO_01','PRAI_NUM_03','PRAI_DATA_15,','ENABLED','VFB_EV_GEN.EXT_VAL_DISABLE_PHY_DAMAGE(:PGIT_POL_RISK_ADDL_INFO_01.PRAI_POL_SYS_ID,
    :PGIT_POL_RISK_ADDL_INFO_01.PRAI_END_NO_IDX,
    :PGIT_POL_RISK_ADDL_INFO_01.PRAI_END_SR_NO,
    :PGIT_POL_RISK_ADDL_INFO_01.PRAI_LVL1_SYS_ID,
    :PGIT_POL_RISK_ADDL_INFO_01.PRAI_CODE_02,
    :PGIT_POL_RISK_ADDL_INFO_01.PRAI_NUM_03,:P_FLAG_OUT)',1,null,'N','01','VALIADTION',null,null,'PREMIA',
    to_date('19-SEP-07','DD-MON-RR'),'WHEN-VALIDATE-ITEM','0','1');
    Insert into IM_INSTANCE_EXT_VAL_FRM (IEVF_SYS_ID,IEVF_INST_CODE,IEVF_PROG_CODE,IEVF_BLK_NAME,IEVF_TRG_FLD_NAME,IEVF_ACT_FLDS,IEVF_ACTION,IEVF_PROC,IEVF_SRNO,IEVF_ERR_NO,IEVF_ERR_YN,IEVF_APP_CODE,IEVF_REMARKS,IEVF_UPD_UID,IEVF_UPD_DT,IEVF_CR_UID,IEVF_CR_DT,IEVF_TRG_NAME,IEVF_CLEAR_FLD_YN,IEVF_VALIDATE_YN) values (IEVF_SYS_ID.NEXTVAL,'APV-QQ-03','PGIT6_03','PGIT_POL_RISK_ADDL_INFO_01','PRAI_NUM_03',null,'VALIDATE','VFB_EV_GEN.EXT_VAL_VEHICLE_AGE(:PGIT_POL_RISK_ADDL_INFO_01.PRAI_POL_SYS_ID,     :PGIT_POL_RISK_ADDL_INFO_01.PRAI_PSEC_SYS_ID,
    ''APV'',
    ''APV'',
    :PGIT_POL_RISK_ADDL_INFO_01.PRAI_NUM_03,
    :PGIT_POL_RISK_ADDL_INFO_01.PRAI_NUM_07,
    :PGIT_POL_RISK_ADDL_INFO_01.PRAI_NUM_08,
    :P_FLAG_OUT,
    :PGIT_POL_RISK_ADDL_INFO_01.PRAI_NUM_35_OUT) ',3,null,'N','01','VALIADTION',null,null,'PREMIA',to_date('19-SEP-07','DD-MON-RR'),'WHEN-VALIDATE-ITEM','1','1');
    Insert into IM_INSTANCE_EXT_VAL_FRM (IEVF_SYS_ID,IEVF_INST_CODE,IEVF_PROG_CODE,IEVF_BLK_NAME,IEVF_TRG_FLD_NAME,IEVF_ACT_FLDS,IEVF_ACTION,IEVF_PROC,IEVF_SRNO,IEVF_ERR_NO,IEVF_ERR_YN,IEVF_APP_CODE,IEVF_REMARKS,IEVF_UPD_UID,IEVF_UPD_DT,IEVF_CR_UID,IEVF_CR_DT,IEVF_TRG_NAME,IEVF_CLEAR_FLD_YN,IEVF_VALIDATE_YN) values (IEVF_SYS_ID.NEXTVAL,'APV-QQ-03','PGIT6_03','PGIT_POL_RISK_ADDL_INFO_01','PRAI_NUM_03','PRAI_DATA_15,','DEFAULT','VFB_EV_GEN.DEFAULT_PHYSICAL_DAMAGE_SYMBOL(:PGIT_POL_RISK_ADDL_INFO_01.PRAI_POL_SYS_ID,
    :PGIT_POL_RISK_ADDL_INFO_01.PRAI_PROD_CODE,
    :PGIT_POL_RISK_ADDL_INFO_01.PRAI_PSEC_SYS_ID,
    ''APV'',
    :PGIT_POL_RISK_ADDL_INFO_01.PRAI_NUM_03,
    :PGIT_POL_RISK_ADDL_INFO_01.PRAI_NUM_07,
    :PGIT_POL_RISK_ADDL_INFO_01.PRAI_CODE_03,
    :PGIT_POL_RISK_ADDL_INFO_01.PRAI_CODE_02,
    :P_FLAG_OUT,
    :PGIT_POL_RISK_ADDL_INFO_01.PRAI_DATA_15_OUT)',2,null,'N','01','DEFAULT',null,null,'PREMIA',to_date('30-AUG-07','DD-MON-RR'),'WHEN-VALIDATE-ITEM','0','1');
    Insert into IM_INSTANCE_EXT_VAL_FRM (IEVF_SYS_ID,IEVF_INST_CODE,IEVF_PROG_CODE,IEVF_BLK_NAME,IEVF_TRG_FLD_NAME,IEVF_ACT_FLDS,IEVF_ACTION,IEVF_PROC,IEVF_SRNO,IEVF_ERR_NO,IEVF_ERR_YN,IEVF_APP_CODE,IEVF_REMARKS,IEVF_UPD_UID,IEVF_UPD_DT,IEVF_CR_UID,IEVF_CR_DT,IEVF_TRG_NAME,IEVF_CLEAR_FLD_YN,IEVF_VALIDATE_YN) values (IEVF_SYS_ID.NEXTVAL,'APV-QQ-03','PGIT6_03','PGIT_POL_RISK_ADDL_INFO_01','PRAI_NUM_03',null,'VALIDATE','VFB_EV_GEN.EXT_VAL_PHY_DAMAGE(:PGIT_POL_RISK_ADDL_INFO_01.PRAI_POL_SYS_ID,
    :PGIT_POL_RISK_ADDL_INFO_01.PRAI_END_NO_IDX,
    :PGIT_POL_RISK_ADDL_INFO_01.PRAI_END_SR_NO,
    :PGIT_POL_RISK_ADDL_INFO_01.PRAI_LVL1_SYS_ID,
    :PGIT_POL_RISK_ADDL_INFO_01.PRAI_CODE_02,
    :PGIT_POL_RISK_ADDL_INFO_01.PRAI_NUM_03,
    :P_FLAG_OUT,
    :PGIT_POL_RISK_ADDL_INFO_01.PRAI_DATA_15_OUT)',9,null,'N','01','VALIADTION',null,null,'PREMIA',
    to_date('19-SEP-07','DD-MON-RR'),'WHEN-VALIDATE-ITEM','1','1');
    script which is taken from Sql Developer and got error while running in SQL* PLUS
    Following error was raised on running the script in SQL * PLUS
    5 rows deleted.
    1 row created.
    1 row created.
    1 row created.
    SP2-0734: unknown command beginning ":P_FLAG_OU..." - rest of line ignored.
    SP2-0734: unknown command beginning ":PGIT_POL_..." - rest of line ignored.
    SP2-0734: unknown command beginning "to_date('1..." - rest of line ignored.

  • How to append to next line using RandomAccessFile writeBytes

    Hi,
    How do you append to the next line using RandomAccessFile with writeBytes()
         static public void append(String strfilename, String strRecord)
              RandomAccessFile file;
              try
                   file = new RandomAccessFile(new File(strfilename), "rw");
                   file.seek(file.length());
                   file.writeBytes(strRecord);
                   file.close();
              catch(Exception e)
                   System.exit(1);
    Thanks,
    John

    At this point there is no next line or return key in SMS or BBM, a lot of people have asked for it. It exists on all the other apps for writing, but not on SMS and BBM.  Hopefully BB releases this simple fix for the messaging..

  • Get all object using RandomAccessFile

    hi friends,
    i have one log file and this log file contain some object. and i am used Serializable Interface.
    i know basically object are not readable format, but consider log file(logInfo.log) contain some object like:
    12 javasun
    20 sunjava
    38 java
    96 sun
    like wise
    am using RandomAccessFile class and this my
    raf.writeInt(baos.size());
    raf.write(baos.toByteArray());
    raf.seek(0);
    int a = 0;
    while(true)
    a = raf.readInt();
    System.out.println("The pointer Value : " + a);
    byte[] b = new byte[a+4];
    int x=(int)raf.getFilePointer();
    System.out.println("file Pointer : " + x);
    raf.read(b,x,a);
    ByteArrayInputStream bais = new ByteArrayInputStream(b,x,a);
    ObjectInputStream ois = new ObjectInputStream(bais);
    Record rec = (Record)ois.readObject(); //here record is object
    System.out.println("The object : "+rec.getAttributes());
    using this code i got below result
    12 javasun
    but i can't get all object from the file(logInfo.log)
    how can i get all object? help me!!!...
    Thank You

    ok, sir
    i tried and i got all object from the file. Thank
    you,
    and,
    if i need last two object from file(logInfo.log)
    like
    38 java
    96 sun
    how can i get? please give some clue or code
    Thank youSince you don't have a set size for the objects, then you will have to read through the entire file always keeping the last two objects, and as soon as the read fails return them.
    As I said in your first thread, however, you would be much better off writing the objects with a set size (i.e. calling ByteArrayOutputStream(size) with a single max size rather than ByteArrayOutputStream( ) ) as you would then be able to use seek adding 4 (for the int) to size and multiplying by the position of the recordset you want to read (0 for the first). You would then, also be able to overwrite records and the such (which is the usually one of the main reasons for using something like RandomAccessFile, i.e. creating a Flat DB-Like File).
    Edit:
    And you would probably lose the int, then anyway (when using a set size), as it wouldn't be needed.

  • Differnce between using RandomAccessFile and Outputstream

    Hi,
    I'm implementing a download manager , i read some source using RandomAccessFile and the other using Outbutstream and buffedOutputstream
    so any one can give me a quick summary between them and which is better ?

    BigDaddyLoveHandles wrote:
    sabre150 wrote:
    BigDaddyLoveHandles wrote:
    BigDaddyLoveHandles wrote:
    It's useless to speculate about unseen code written by an unknown hand.That's my {color:green}Phrase Of The Day.{color}Interesting that I also used the word 'speculate' but my brain must be slower than yours since I was a minute behind you!Don't you know that on Fridays it's useless trying to keep up with me? I wear my Ninja outfit!:-) I'm surprised you can get one that fits!

  • The concurrent io problem when using RandomAccessFile

    Hi:
    In my application,I have to export the tomcat log(the log file like "localhost_access_log.2010-10-13") to database and the do some analisis.
    My way:
    start to export log at 00:05:00 every day,at this moment just read the log whose date before yesterday.
    For example,at 2010-12-12 00:05:00,the log of 2010-12-11... 2010-12-01 ..2010-11-12...(just check the nearest 30 days).
    All of these data are put into one table named "log".
    If log of one day is exported successfully,insert one record to another table named 'logrecord'.
    //main code fragment:
         public void start() {
              //start the push export work once the server startup.
              run();
              //start the schedule work
              new ScheduledThreadPoolExecutor(5).scheduleAtFixedRate(this, getStartTime(), 24 * 3600,
                        TimeUnit.SECONDS);
         //return the left time(from now to 00:05:00 of tomorrow)
         private long getStartTime() {
              Date d = new Date();
              long t = (DateUtil.getNextDayAtMiddleTime(d).getTime() - d.getTime()) / 1000 + 300;
              return t;
         @Override
         public void run() {
              Date days[] = DateUtil.getSeveralDayRangeByTime(30); //just the nearest 30 days.
              for (Date d : days) {
                   if (exist(d)) {
                        continue;
                   exportLogByDate(d);
    It works for now expect we can not anlyzer data of today.
    However we need it now.
    As far as I thought,I want to create a new table which owns the same structure of the former table "log" used to hold the log of "today" only.
    At 00:05:00 of every day,after the normal log exporting(export the nearest 30 days'log but today),export the log of today.
    It sounds easy,read the content,parser,filter,insert,just like what I did.
    But,the tomcat log file is saved by day.So in my normal log exporting,the log file(nearest 30 days) are not be used by tomcat,I can open/close it as I like.
    However if I tried to read the log of today,since the log file maybe used by tomcat for inserting log.
    I prefer to use the RandomAccessFile to read the log of today:
    But I am coufused by the concurrent io problem:what is going on if I am reading a line while tomcat is writing the line?
    Here is my test exmaple:
    package com.test;
    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.RandomAccessFile;
    import org.junit.BeforeClass;
    import org.junit.Test;
    public class TestMain {
         private static File          file;
         private static long          pos; //record the position of last time
         private static Thread     writterThread;
         @BeforeClass
         public static void init() {
              file = new File("D:/random.txt");
              // build the thread for simulating the tomcat write log
              writterThread = new Thread(new Runnable() {
                   @Override
                   public void run() {
                        FileWriter fw;
                        try {
                             fw = new FileWriter(file);
                             BufferedWriter bw = new BufferedWriter(fw);
                             int i = 0;
                             while (true) {
                                  i++;
                                  bw.append(i + " added to line...");
                                  bw.append("\r\n");
                                  bw.flush();
                                  Thread.sleep(5000);
                        } catch (IOException e) {
                             e.printStackTrace();
                        } catch (InterruptedException e) {
                             e.printStackTrace();
         @Test
         public void testRandomRead() throws IOException, InterruptedException {
              writterThread.start();
              try {
                   RandomAccessFile raf = new RandomAccessFile(file, "r");
                   String line;
                   while ((line = raf.readLine()) != null) {
                        System.out.println(line);
                   pos = raf.getFilePointer();
                   raf.close();
                   // read the file by 30 seconds within 2 min,just for test)
                   for (long m = 0; m < 1000 * 60 * 2; m += 30000) {
                        raf = new RandomAccessFile(file, "r");
                        raf.seek(pos);
                        while ((line = raf.readLine()) != null) {
                             System.out.println(line);
                        pos = raf.getFilePointer();
                        raf.close();
                        Thread.sleep(30000);
              } catch (FileNotFoundException e) {
                   e.printStackTrace();
    The normal output is something like:
    1 added to line...
    2 added to line...
    3 added to line...
    4 added to line...
    5 added to line...
    However I always get the following output:
    1
    added to line...
    2 added to line...
    3 added to line...
    4 added to line...
    5
    added to line...
    That's to say,the RandomAccessFile is reading the line which has not been completed by tomcat.
    So,I have two questions now:
    1) How about my normal log exporting? Is there anything can be improved?
    2) How to slove the concurrent io problem when export log of today?

    Peter Lawrey wrote:
    You can;
    - check the length to see if it has grown since the last time it was written to. If it has shrunk, start from the start of the file.
    - if longer, open the file from the last point read.
    - read the text up to the last newline in the file. (might be no new lines)
    - close the file and remember where you were up to. (the start of the last incomplete line.
    - wait a bit and repeat.But how to decide if one line is completed?
    Also,how about if the randomaccessfile can not stop?
    For example,start the work at 02:00,it read the tomcat log file line by line and export them to db,and during this time,the tomcat keep writing log to the same file(user request the server all the time), and then the randomaccessfile will keeping reading accordingly,when it is 03:00,the last task is not completed,but a new task should start,how to control this?

  • How to insert a number using ADO or OLEDB by oracle provider

    I create a talbe .
    Create Table A
    (id number(7));
    I use ADO to access the table a;
    _ConnectionPtr pConn=NULL;
    pConn.CreateInstance(__uuidof(Connection));
    _RecordsetPtr pRst=NULL;
    pRst.CreateInstance(__uuidof(Recordset));
    pConn->Provider="OraOLEDB.Oracle.1";
    try
         pConn->Open("","ISVISION","ISVISION",NULL);
         pRst->CursorLocation=adUseClient;
         pRst->Open("A",pConn.GetInterfacePtr(),adOpenStatic,adLockOptimistic,adCmdTable);
         pRst->AddNew();
         pRst->Fields->Item[0L]->Value=100L;
    //It raise a exception,why?
    //If I convert the datetype of "ID" to CHAR(7)
    //and pRst->Fields->Item[0L]->Value=L"100",it is ok.
         pRst->Update();
         pRst->Close();
         pConn->Close();
    catch (_com_error& e)
         MessageBox(e.Description(),"error",MB_OK|MB_ICONWARNING);
         return ;
    if (pConn)
    pConn.Release();
    if (pRst)
    pRst.Release();
    I create a table A。
    create table A
         ID number(7)
    Now ,I use OLE DB to access the table A;
    struct CIsA
         CIsA()
              memset(this, 0, sizeof(*this));
    public:
         DB_NUMERIC m_ID;
         BEGIN_COLUMN_MAP(CIsA)
              COLUMN_ENTRY_PS(1, 7, 0, m_ID)
         END_COLUMN_MAP()
    DEFINE_COMMAND(CIsA, _T("SELECT ID FROM A"))
    CDataSource DataSource;
    HRESULT hrt=DataSource.Open(_T("OraOLEDB.Oracle.1"),NULL,_T("ISVISION"),_T("ISVISION"));
    CSession Session;
    hrt=Session.Open(DataSource);
    CDBPropSet propset(DBPROPSET_ROWSET);
    propset.AddProperty(DBPROP_IRowsetChange, true);
    propset.AddProperty(DBPROP_UPDATABILITY,
         DBPROPVAL_UP_INSERT | DBPROPVAL_UP_CHANGE | DBPROPVAL_UP_DELETE);
    CCommand<CAccessor<CIsA> > Command;
    Command.Open(Session,NULL,&propset);
    tcscpy((TCHAR*)Command.mID.val,_T("1245"));
    Command.m_ID.sign=1;
    hrt=Command.Insert();//It is wrong,why?
    Command.Close();
    Session.Close();
    DataSource.Close();
    In Fact,the two problems is the same. The key of problem is how to insert a number into oracle.
    help me! thank you.

    hi
    create a table something like this.
    create table image(
    Image_Id number(5),
    Image    blob);create a form with the same table and use the following code.
    when-button-pressed trigger.
    read_image_file('c:\image_name.jpg' , 'jpg' , 'image.image');if its correct/helpful please mark it thanks.
    sarah

Maybe you are looking for