Escaping the pipe (|) character in java

Hi,
I am trying to run the following command in java
ps -ef -o pid,args | grep init | grep -v grep
The code is
       try {
                Runtime rt = Runtime.getRuntime();
                Process pr = rt.exec("ps -ef -o pid,args \\| grep init \\| grep -v grep ");
                BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream()));
                String line=null;
                while((line=input.readLine()) != null) {
                    System.out.println(line);
                int exitVal = pr.waitFor();
                System.out.println("Exited with error code "+exitVal);*/
            } catch(Exception e) {
                System.out.println(e.toString());
                e.printStackTrace();
            }I am not able to run this command in Java. And, I guess the problem lies in escaping the pipe symbol. I am not sure how to do that. Can anyone please help me on that?
Thanks,
Juggie

The problem is not escaping; it's that the pipe character is interpreted by the shell. You should be passing that command line to the shell, e.g. "sh ps -ef -o pid,args | grep ..."

Similar Messages

  • How to escape the special character ' (ascii 39) in a select query?

    Hi,
    does anybody know how to escape the special character ' (ascii 39) in a select query?
    I've tried a lot of ways but nothing seems to work, for example I try to get all
    names in table foo where coloumn name contains a '-sign (ascii 39)
    select name from foo where name like '%\'%';
    select name from foo where name like '%{'}%';
    select name from atg_horse where name like '%chr(39)%'
    ... but neither works, I end up with a ORA-01756: quoted string not properly terminated
    I would apriciate any help
    /Carl-Michael

    friends
    thanks for ur time and effort that u gave to reply to my problem.
    But my main problem is that when my application (VC++ 7) fires the following query in the oracle database , it does not return any rows.
    SELECT count(*) FROM ORGANISATION WHERE UPPER(ORGANISATION.ORGANISATIONNAME)
    LIKE N'β%' ORDER BY ORGANISATION.ORGANISATIONNAME
    the above question in the previous thread was just to check on sql plus as it's editor does not support unicode characters.

  • How to escape the special character ' (ascii 39) in a query

    Hi,
    does anybody know how to escape the special character ' (ascii 39) in a select query?
    I've tried a lot of ways but nothing seems to work, for example I try to get all
    names in table foo where coloumn name contains a '-sign (ascii 39)
    select name from foo where name like '%\'%';
    select name from foo where name like '%{'}%';
    select name from atg_horse where name like '%chr(39)%'
    ... but neither works, I end up with a ORA-01756: quoted string not properly terminated
    I would apriciate any help
    /Carl-Michael

    Use two single quotes inside your literals to represent one single quote.
    For example, this would find my name:
    SELECT *
      FROM emp
    WHERE name = 'Michael O''Neill';
    Michael O'Neill
    (acutely aware of the apostrophe issues in the world)

  • Escaping the scan character for insert

    I wanted to do something like this in Lotus Notes:
    create table test(val varchar2(10));
    Create or replace procedure test1 AS
    begin
    insert into test values ('A& B');
    end;
    That is inserting the scan character '&'
    as part of the string
    but the ODBC driver always prompts me for a value.
    Notes string vsql='A& B';
    Any suggestion?
    Thanx

    Use a leading backslash. The \" escapes a quote.

  • Plz help me in escaping the starting character

    Actually i'm getting the name from textfeild and storing it in string.but wht i want is whn the user enters the first character i.e., either " or | in the Textfeild i need to trim the string i.e., it should not take those characters if they give them also wht should i do for this .plz help me it is urgent

    You could try having a keypress action listener. If the user presses a key that you don't want to show, the action listener can handle the event.

  • Escaping the comment character

    I need to include the following in a string but can't get it to escape the comments characters.
    " select /*+ORDERED*/ field1 ... ";
    Thanks in advance,
    Grey

    The comment characters ("/*" and "*/") shouldn't need to be escaped within the context of a String value; is it the compiler that is having trouble with the value, or the database? What error messages are you receiving?

  • Using html in cf report builder and escaping the & ampersand character

    Some of the data we collect is entered via a WYSIWYG editor.  Therefore formatting such as bold, italic etc is translated into HTML.
    The text could also contain special characters/accented characters, again these are translated into their html equivalents.
    In CF Report Builder, I have set the XHTML Text formatting to TRUE.  However the report won't render the text in these boxes.  From what I can see it doesn't like the '&' character (ampersand).
    I have read elsewhere that report builder is limited in the characters etc that it can read and that I should translate the values.  I ended up doing this in the database to try and save some time.
    CREATE  OR REPLACE FUNCTION translatexhtmltoasci(var_text IN appendix3%TYPE)
      RETURN clob
    ISvar_translated_text clob;BEGIN
     select  replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(re place(replace(
      replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(re place(replace
      (replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(r eplace(replace
      (replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(r eplace(replace
      (replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(r eplace(replace
      (replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(r eplace(replace
      (replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(r eplace(replace
      (replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(r eplace(replace
      (replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(r eplace(replace
      (replace(replace(replace(replace(replace(replace(replace(replace(replace(
    var_text , chr(38) || 'lt;', chr(60))
      , chr(38) || 'gt;', chr(62))
      , chr(38) || 'euro;', chr(49792))
      , chr(38) || 'iexcl;', chr(49825))
      , chr(38) || 'cent;', chr(49826))
      , chr(38) || 'pound;', chr(49827))
      , chr(38) || 'curren;', chr(49828))
      , chr(38) || 'yen;', chr(49829))
      , chr(38) || 'brvbar;', chr(49830))
      , chr(38) || 'uml;', chr(49832))
      , chr(38) || 'copy;', chr(49833))
      , chr(38) || 'ordf;', chr(49834))
      , chr(38) || 'laquo;', chr(49835))
      , chr(38) || 'not;', chr(49836))
      , chr(38) || 'shy;', chr(49837))
      , chr(38) || 'reg;', chr(49838))
      , chr(38) || 'macr;', chr(49839))
      , chr(38) || 'deg;', chr(49840))
      , chr(38) || 'plusmn;', chr(49841))
      , chr(38) || 'sup2;', chr(49842))
      , chr(38) || 'sup3;', chr(49843))
      , chr(38) || 'acute;', chr(49844))
      , chr(38) || 'micro;', chr(49845))
      , chr(38) || 'para;', chr(49846))
      , chr(38) || 'middot;', chr(49847))
      , chr(38) || 'cedil;', chr(49848))
      , chr(38) || 'sup1;', chr(49849))
      , chr(38) || 'ordm;', chr(49850))
      , chr(38) || 'raquo;', chr(49851))
      , chr(38) || 'frac14;', chr(49852))
      , chr(38) || 'frac12;', chr(49853))
      , chr(38) || 'frac34;', chr(49854))
      , chr(38) || 'iquest;', chr(49855))
      , chr(38) || 'Agrave;', chr(50048))
      , chr(38) || 'Aacute;', chr(50049))
      , chr(38) || 'Acirc;', chr(50050))
      , chr(38) || 'Atilde;', chr(50051))
      , chr(38) || 'Auml;', chr(50052))
      , chr(38) || 'Aring;', chr(50053))
      , chr(38) || 'AElig;', chr(50054))
      , chr(38) || 'Ccedil;', chr(50055))
      , chr(38) || 'Egrave;', chr(50056))
      , chr(38) || 'Eacute;', chr(50057))
      , chr(38) || 'Ecirc;', chr(50058))
      , chr(38) || 'Euml;', chr(50059))
      , chr(38) || 'Igrave;', chr(50060))
      , chr(38) || 'Iacute;', chr(50061))
      , chr(38) || 'Icirc;', chr(50062))
      , chr(38) || 'Iuml;', chr(50063))
      , chr(38) || 'ETH;',

    I also stuck with this . Still no answer, no solution

  • The pipe "|" does not work in the Windows command console.

    This is a very weird problem. I am using 64-bit Windows VISTA command window for very long time and it just suddenly do not work with the pipe character anymore. I have checked the PATH and PATHEXT in Administrator mode and they look OK.
    Detail below:
    For example, the "dir" work as expected.
    C:\newcmd>dir *.txt
     Volume in drive C has no label.
     Volume Serial Number is 4CD2-5B84
     Directory of C:\newcmd
    10/31/2014  11:33 PM               737 adder.txt
    04/05/2015  03:21 PM         1,890,696 au01.txt
    12/17/2014  10:40 PM             4,204 bintree.txt
    07/26/2011  10:47 PM         3,298,568 ke30-07-2011.txt
    If pipe to a VBScript file below, the error message shows up. The error message is actually the content of %PATHEXT% environment variable:
    C:\newcmd>dir *.txt|cscript //nologo cut.vbs -c "1-12"
    '.COM;.EXE;.BAT;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.REX;.REXG;.REXP;.CMD;'
    is not recognized as an internal or external command, operable program or batch file.
    The VBScript works fine without the "|":
    C:\newcmd>cscript //nologo cut.vbs
    Usage:cut "<delimiter>" "<column 0>,<column 1>,..."
    Example:cut "|" "0,1,8"
    What is going on and how to fix it? Help?
    C:\newcmd>echo %PATH%
    C:\Windows\system32;C:\Windows\System32\Wbem;C:\Program Files (x86)\CyberLink\Power2Go;C:\Program Files (x86)\Java\jre1.6.0_07\bin;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Program Files\nodejs\;C:\Program Files\ooRexx;c:\
    C:\newcmd>echo %PATHEXT%
    .COM;.EXE;.BAT;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.REX;.REXG;.REXP;.CMD;

    Hi,
    Please check if this happens in [https://support.mozilla.com/en-US/kb/Safe%20Mode Safe Mode.] Safe Mode is a temporary diagnostic feature and you can exit and start Firefox normally again. The installed '''Extensions''', themes ('''Appearance''') and '''Plugins''' are disabled in safe mode.
    [http://kb.mozillazine.org/Problematic_extensions Problematic Extensions]
    [https://support.mozilla.com/en-US/kb/Troubleshooting%20extensions%20and%20themes Troubleshooting Extensions and Themes]
    [http://support.mozilla.com/en-US/kb/Uninstalling+add-ons Uninstalling Add-ons]
    [http://kb.mozillazine.org/Uninstalling_toolbars Uninstalling Toolbars]

  • How to escape the single quote from email value?

    Hi,
    Is there any way to escape the special character single quote from the email value.
           String ownerQry = "Select Id, email from User where email in('0000'";
            for(int i=0; i<accountData.length; i++)
                ownerQry += ",'" + accountData.TEAM_EMAIL+"'";
    ownerQry += ")";
    QueryResult qrTeam = sfdcCtrl.query(ownerQry);
    When i tried to set the email value on a custom object, its throwing the error as below  and failed to update. <xml-fragment xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sf="urn:fault.enterprise.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><faultcode>sf:MALFORMED_QUERY</faultcode><faultstring>MALFORMED_QUERY:
    '[email protected]','brenden.o'[email protected]','[email protected]'
    ^ ERROR at Row:1:Column:963 expecting a right parentheses, found 'connor'</faultstring><detail><sf:fault xsi:type="sf:MalformedQueryFault" xmlns:sf="urn:fault.enterprise.soap.sforce.com"><sf:exceptionCode xmlns:sf="urn:fault.enterprise.soap.sforce.com">MALFORMED_QUERY</sf:exceptionCode><sf:exceptionMessage xmlns:sf="urn:fault.enterprise.soap.sforce.com">
    '[email protected]','brenden.o'[email protected]','[email protected]'
    ^ ERROR at Row:1:Column:963 expecting a right parentheses, found 'connor'</sf:exceptionMessage><sf:row xmlns:sf="urn:fault.enterprise.soap.sforce.com">1</sf:row><sf:column xmlns:sf="urn:fault.enterprise.soap.sforce.com">963</sf:column></sf:fault></detail></xml-fragment>

    Thanks Dr.Clap.
    I think its very tricky to implement this.
    Here is the SOQL query. i am passing all the email values.
    Select Id, email from User where email in('0000','o\'[email protected]','[email protected]')
    These values are coming from oracle DB table in the form of array accountData[].TEAM_EMAIL
            String ownerQry = "Select Id, email from User where email in('0000'";
            for(int i=0; i<accountData.length; i++)
               ownerQry += ",'" + accountData.TEAM_EMAIL+"'";
    ownerQry += ")";the array value may contain the email with single quote before @gmail.com which i need to ignore. :-( i think this is very tricky. who knows the solution for this?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Webloc files won't synchronize- pipe character

    Hi
    I have 3 weblocs files in a folder, 1 syncs with no problem, the other 2 won't.
    ok :
    Adobe Edge Preview Resources - Adobe Labs
    not ok :
    Beginner's guide to Adobe Edge Preview 3 | Adobe Developer Conne
    HTML5 tools, Animation tools - Adobe Edge Preview | Adobe Labs
    It seems that it has to do with the pipe character |
    Problem is that i have a failure notification every time CC tries to sync, which is annoying.

    Hi Ken, by that time i had understood the pipe problem, which is a good start
    My main concern, now, and it's still valid, is the permanent notification. I had to rename those files to make it go away.
    If for any reason I have many folders with any impossible characters, and there's a lot of them, it means i will have to edit each file manually :
    those I knew (same problem on mac)
    : (colon)
    / (forward slash)
    \ (backslash)
    This one I discovered thanks to that problem
    | (vertical bar or pipe)
    These I had no idea, but feel like trouble to come :
    < (less than)
    > (greater than)
    " (double quote)
    ? (question mark)
    * (asterisk)
    I mean, the asterisk, knowing that NO keyboard i've seen has a × multiplication sign, and we're dealing with graphic files which can have dimensions in it, I'm sometimes naming MyFile-web-600x800px.png or MyFile-web-600*800px.png and having no problem on a mac might be a problem for later.

  • Inserting broken pipe character in DB from Java creating problem

    Hello experts,
    We want to insert a broker pipe character in oracle 10g from java.
    But it get changed to pipe character.
    We are having japanese client for which we want to maintain this kind of character.
    If someone know the solution, please update.

    Hi,
    I understand your explanation.
    It is not possible to put actual code, that's complex and coupled with other things.
    I like to share the scenario where it failing,
    1. Broken Pipe character(double byte (\u00fa\u0055)) is put along with other japanese long text in a *.txt file.
    2. A java file reads the above *.txt file and inserts the file text in a table column in oracle.
    The .txt file is saved in Shift_JIS encoding.
    In java file, the same *.txt file is read using 'CP943C' charset and written into database.
    So as per your suggestion I have to compare literal first and than if I found broken bar in file, I need to change it with specified unicode.
    Is that so?
    --Saurabh.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • How to escape the character in a string?

    I have the following code that is causing an error. I'm
    attempting to use < (less than) character in a string that is
    part of a dynamic query:
    <cfif url.age eq 1>
    <cfset askAge = " < 15">
    <cfelseif url.age eq 10>
    <cfset askAge = " Between 56 and 60">
    <cfelseif url.age eq 11>
    <cfset askAge = " > 60">
    </cfif>
    The error occurs as a result of the line <cfset askAge = "
    < 15">. The > 60 works fine. What I need is to build the
    SQL statement SELECT * FROM myTable WHERE age < 15
    ColdFusion sets the string properly but when I try to run the
    query I guess it thinks I'm trying to open a tag. The exact error
    is:
    The content beginning "< " is not legal markup. Perhaps
    the " " (&#20;) character should be a letter.
    The content beginning "< " is not legal markup. Perhaps
    the " " () character should be a letter.
    I can't use the ASCII code for this character as the database
    will obviously crap out.
    Any help would be greatly appreciated and many thanks in
    advance.
    Dave

    Dave,
    What if you passed off the output of the lt/gt symbols to the
    query itself?
    Something like,
    <cfif url.age eq 1>
    <cfset compareOperator = "less"/>
    <cfset askAge = "15">
    <cfelseif url.age eq 10>
    <cfset compareOperator = "between"/>
    <cfset askAge = " 56 and 60">
    <cfelseif url.age eq 11>
    <cfset compareOperator = "greater"/>
    <cfset askAge = "60">
    </cfif>
    Then in the query:
    <cfquery name="qTest" datasource="dsn">
    SELECT * FROM myTable
    WHERE age
    <cfswitch expression="#compareOperator#">
    <cfcase value="less">
    <
    </cfcase>
    <cfcase value="greater">
    >
    </cfcase>
    <cfcase value="between">
    BETWEEN
    </cfcase>
    <cfdefaultcase>
    =
    </cfdefaultcase>
    </cfswitch>
    #askAge#
    </cfquery>
    Probably a better way, at least a more efficient way, but
    just a thought...cfswitch processed pretty quickly and this would
    remove any issues with trying to use <> symbols.
    Cheers,
    Craig

  • Escaping the "&" character

    Hi,
    I am using a shuttle item that retrieves data for the left shuttle list using an Ajax call but where the data has an ampersand ("&") in it, seems to prevent all of that data set appearing.
    Can someone please suggest the best approach to prevent this from happening so that any information that has a ampersand ("&") between data, functions correctly - basically need to escape the "&".
    Thanks.
    Tony.

    I only think that worked for me was to use TRANSLATE.
    select translate(column, '&','+') from table
    Then I was able to get the data displayed (P.S., you should also transalte quotation marks (single and double) as well.
    Robert

  • Display pop ups in the jsp by using Java script

    Hi
    can any body say ,how to display pop ups in the jsp by using Java script ?

    that's correct. You can use the below code for AJAX request.
    <script type="text/javascript">
    var httpObject = getHTTPObject();
    //create XMLHttpRequest object
    function getHTTPObject() {     
         var xmlhttp;
         if (window.XMLHttpRequest) // if Mozilla, Safari etc
              xmlhttp = new XMLHttpRequest();
         else if (window.ActiveXObject){ // if IE
              try {
                   xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
              catch ( e ){
                   try{
                        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                   catch ( e ){}
         return xmlhttp;
    //define the function to send the request
    function sendRequest(){
        var currDesc = document.getElementById("description").value;
        var URL =  "manageMaintAction.do"; //action mapping in your struts-config
        var queryString = "currDesc="+escape(currDesc); //get the currDesc value in your action class like request.getParameter("currDesc")
        httpObject.open( "Post", URL, true );
        httpObject.onreadystatechange = cbFn;
        httpObject.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded");
        httpObject.send(queryString);
    //callback fn
    function cbFn() {
        if (httpObject.readyState == 4)
             if (httpObject.status == 200)
              var result = httpObject.responseText;
              alert(result);
    </script>

  • 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.");
    }

Maybe you are looking for

  • How does RAC determine which instance number to run on which node

    Good afternoon I am trying to script a process and I need to identify how RAC decides which node runs which instance. Is it the first one of the pair added to the cluster that runs node 1 or is there some other piece of information that I need to wor

  • Why is the "iDVD" gray in the Share menu?

    I want to burn a movie to DVD. In the Share menu, the iDVD is gray and cannot be selected. This is not true for other projects. How do I find out why and how do I fix it? Thanks in advance for your help. Love & Peace, Grace

  • CS4 Camera Raw: Can't open multiple files ???

    This is a very strange problem. I recently installed CS4 and started using it with RAW files from a Canon 5D Mark II camera. When selecting File -> Open As ->Camera Raw, I can't seem to select more than one raw file from the file dialog. I can open a

  • Preview opens when Syncing iPhone

    Preview keeps opening every time i connect my iPhone 4s running iOS 7.0.4 to my iMac running 10.9.1 Mavricks. See screenshot. Its rather annoying, how to get this to stop happening? I just started recently, I can't remmember what I did if anything to

  • Crashing after sleep...

    Hi all, Leopard installed without issue. Unfortunately, since installing my computer crashes after it's been asleep. I have a new iMac with 2 gig of RAM. I have hooked up a backup drive to use time-machine. This doesn't appear to be the problem. Here