How to write empty line in text file

hey
i want to insert one empty line in text file.
how to write this.
i declared
data: emptyrec(240) type c value space,
and used
TRANSFER emptyrec to e_file.
but its not inserting empty line in the record.
is there any special way have to do.
ambichan.

hai anand,
I am posting the code snippet.
i have commented that transfer line in '----
' like this
pls refer below.
ambichan
DATA: PAGENO(4) TYPE N VALUE 1,
      DATAKBN(2) TYPE N VALUE 1,
      SUBNO(3) TYPE N VALUE 1,
      VPAGENO(4) TYPE C,
      VDATAKBN(2) TYPE C,
      VSUBNO(3) TYPE C,
      VREC(255) TYPE C,
      VRECORD(255) TYPE C,
      EMPTYREC(255) TYPE C VALUE SPACE,
      VCODE(10) TYPE C,
      VNAME2(35) TYPE C,
      VPAYDAT(10) TYPE C,
      VSGTXT(60) TYPE C VALUE SPACE,
      VSGTXT1(10) TYPE C,
      VKINGAKU(15) TYPE C VALUE SPACE,
      VBIKKO(30) TYPE C VALUE SPACE,
      VBELNR(10) TYPE C VALUE SPACE,
      VDMBTR(15) TYPE C,
      VGLT0-KSLVT(15) TYPE C,
      VGLT0-TSL01(15) TYPE C,
      VGLT0-TSL02(15) TYPE C,
      VGLT0-TSL03(15) TYPE C,
      VGLT0-TSL04(15) TYPE C,
      VGLT0-TSL05(15) TYPE C,
      VKIN(15) TYPE C,
      VTEGA(15) TYPE C.
FORM FRM_OUTPUT_DATA.
  SORT ITAB_OUTPUT_SUMMARY BY LIFNR DTYPE.
  SORT ITAB_OUTPUT_ITEMS   BY LIFNR DTYPE BELNR.
IF P_DISP = 'X'."checkボクスを選ぶ場合、ファイル作成処理へ行く
OPEN DATASET E_FILE FOR OUTPUT IN TEXT MODE.
  IF SY-SUBRC <> 0.
  WRITE: 'error',SY-SUBRC.
  EXIT.
  ENDIF.
LOOP AT ITAB_LIFNR.
  PERFORM LISTDATA.
  PAGENO = PAGENO + 1.
  SUBNO = 1.
ENDLOOP.
CLOSE DATASET E_FILE."&#12501;&#12449;&#12452;&#12523;&#12463;&#12525;&#12540;&#12474;
ENDFORM.                               " End of frm_output_data
FORM LISTDATA.
  DATA:
    WK_PAY_AMOUNT  LIKE  BSEG-DMBTR,   " &#32020;&#25903;&#25173;&#38989;&#31639;&#20986;&#29992;
    VWK_PAY_AMOUNT(15) TYPE C,
    GLT0-TSL05_VAL LIKE GLT0-TSL05.
  READ TABLE ITAB_OUTPUT_SUMMARY
         WITH KEY   LIFNR  =  ITAB_LIFNR-LIFNR  DTYPE = 1.
BSIK-DMBTR  =  ITAB_OUTPUT_SUMMARY-DMBTR * WK_RATIO.
  GLT0-TSL01  =  ITAB_OUTPUT_SUMMARY-DMBTR * WK_RATIO.
  READ TABLE ITAB_OUTPUT_SUMMARY
         WITH KEY   LIFNR  =  ITAB_LIFNR-LIFNR  DTYPE = 2. " &#21306;&#20998;&#65306;2
  GLT0-TSL02  =  ITAB_OUTPUT_SUMMARY-DMBTR * WK_RATIO.
  READ TABLE ITAB_OUTPUT_SUMMARY
         WITH KEY   LIFNR  =  ITAB_LIFNR-LIFNR  DTYPE = 3. " &#21306;&#20998;&#65306;3
  GLT0-TSL03  =  ITAB_OUTPUT_SUMMARY-DMBTR * WK_RATIO.
  READ TABLE ITAB_OUTPUT_SUMMARY
         WITH KEY   LIFNR  =  ITAB_LIFNR-LIFNR  DTYPE = 4. " &#21306;&#20998;&#65306;4
  GLT0-TSL04  =  ITAB_OUTPUT_SUMMARY-DMBTR * WK_RATIO.
  READ TABLE ITAB_OUTPUT_SUMMARY
         WITH KEY   LIFNR  =  ITAB_LIFNR-LIFNR  DTYPE = 5. " &#21306;&#20998;&#65306;5
  GLT0-TSL05  =  ITAB_OUTPUT_SUMMARY-DMBTR * WK_RATIO.
glt0-tsl05  =  glt0-tsl05  +  glt0-tsl04.
  WK_PAY_AMOUNT  =  GLT0-TSL05  +  GLT0-TSL04.
CHECK WK_SUBRC = 0.                
  BSEG-KOART = ' '.                    &#24773;&#22577;&#19981;&#35201;
  CLEAR: BSEG-SGTXT, BSEG-DMBTR, TGSBT-GTEXT, BKPF-BELNR.
  BSEG-KOART = 'Y'.                    " &#12501;&#12521;&#12464;&#65306;&#12504;&#12483;&#12480;&#12395;&#30456;&#27578;&#38989;&#12434;&#20986;&#21147;
CLEAR: BSAK-DMBTR.
  READ TABLE ITAB_OUTPUT_SUMMARY
       WITH KEY   LIFNR  =  ITAB_LIFNR-LIFNR  DTYPE = 6.  " &#21306;&#20998;&#65306;6
  BSAK-DMBTR  =  ITAB_OUTPUT_SUMMARY-DMBTR * WK_RATIO.
  WK_PAY_AMOUNT  =  WK_PAY_AMOUNT  -  BSAK-DMBTR.
  WRITE : / PAGENO,
           SUBNO,
           DATAKBN,
           ITAB_LIFNR-LIFNR,
           ITAB_LIFNR-NAME2(25),
           P_PAY_T,
           GLT0-TSL01,
           GLT0-TSL02,
           GLT0-TSL03,
           GLT0-TSL04,
           GLT0-TSL05.
VPAGENO = PAGENO.
VSUBNO = SUBNO.
DATAKBN = 1.
VDATAKBN = DATAKBN.
VCODE = ITAB_LIFNR-LIFNR.
VNAME2 = ITAB_LIFNR-NAME2.
VPAYDAT = P_PAY_T.
VGLT0-TSL01 = GLT0-TSL01.
VGLT0-TSL02 = GLT0-TSL02.
VGLT0-TSL03 = GLT0-TSL03.
VGLT0-TSL04 = GLT0-TSL04.
VGLT0-TSL05 = GLT0-TSL05.
CONCATENATE VPAGENO VSUBNO VDATAKBN VCODE VNAME2 VPAYDAT VSGTXT VKINGAKU
VBIKKO VBELNR VGLT0-TSL01 VGLT0-TSL02 VGLT0-TSL03
VGLT0-TSL04 VGLT0-TSL05 INTO VREC SEPARATED BY ','.
CLEAR: BSAK-DMBTR, BSID-DMBTR, BSAD-DMBTR, BSEG-DMBTR, BSIK-DMBTR,
         WK_10 , WK_11 , GLT0-TSL05.
  READ TABLE ITAB_OUTPUT_SUMMARY
       WITH KEY   LIFNR  =  ITAB_LIFNR-LIFNR  DTYPE = 7.  " &#21306;&#20998;&#65306;7
  BSID-DMBTR  =  ITAB_OUTPUT_SUMMARY-DMBTR * WK_RATIO.
  WK_PAY_AMOUNT  =  WK_PAY_AMOUNT  -  BSID-DMBTR.
&#37109;&#36865;&#26009;&#12398;&#20986;&#21147;&#20966;&#29702;
  READ TABLE ITAB_OUTPUT_SUMMARY
       WITH KEY   LIFNR  =  ITAB_LIFNR-LIFNR  DTYPE = 8.  " &#21306;&#20998;&#65306;8
  BSAD-DMBTR  =  ITAB_OUTPUT_SUMMARY-DMBTR * WK_RATIO.
  WK_PAY_AMOUNT  =  WK_PAY_AMOUNT  -  BSAD-DMBTR.
  READ TABLE ITAB_OUTPUT_SUMMARY
       WITH KEY   LIFNR  =  ITAB_LIFNR-LIFNR  DTYPE = 9.  " &#21306;&#20998;&#65306;9
  BSEG-DMBTR  =  ITAB_OUTPUT_SUMMARY-DMBTR * WK_RATIO.
  WK_PAY_AMOUNT  =  WK_PAY_AMOUNT  -  BSEG-DMBTR.
  READ TABLE ITAB_OUTPUT_SUMMARY
         WITH KEY   LIFNR  =  ITAB_LIFNR-LIFNR  DTYPE = 10.
  WK_10 =     ITAB_OUTPUT_SUMMARY-DMBTR * WK_RATIO.
  READ TABLE ITAB_OUTPUT_SUMMARY
         WITH KEY   LIFNR  =  ITAB_LIFNR-LIFNR  DTYPE = 11.
  WK_11 =     ITAB_OUTPUT_SUMMARY-DMBTR * WK_RATIO.
  GLT0-TSL05  =   WK_PAY_AMOUNT - WK_10 - WK_11.
  WK_PAY_AMOUNT  =  WK_PAY_AMOUNT  -  GLT0-TSL05.
   VWK_PAY_AMOUNT = WK_PAY_AMOUNT.
   VKIN = WK_10.
   VTEGA = WK_11.
   CONCATENATE VREC VWK_PAY_AMOUNT VKIN VTEGA INTO
         VRECORD SEPARATED BY ','.
   TRANSFER VRECORD TO E_FILE.
    WRITE :
            VWK_PAY_AMOUNT,
            WK_10,
            WK_11.
   WRITE:/.
  BSEG-KOART  = 'X'.                   " &#12501;&#12521;&#12464;&#65306;&#35531;&#27714;&#37329;&#38989;&#12434;&#20986;&#21147;
  LOOP AT ITAB_OUTPUT_ITEMS WHERE LIFNR = ITAB_LIFNR-LIFNR
                            AND   DTYPE = 5.          " &#21306;&#20998;&#65306;5
    BSEG-SGTXT   =  ITAB_OUTPUT_ITEMS-SGTXT.          " &#26126;&#32048;&#12486;&#12461;&#12473;&#12488;
    GLT0-KSLVT   =  ITAB_OUTPUT_ITEMS-DMBTR * WK_RATIO.     " &#37329;&#38989;
    TGSBT-GTEXT  =  ITAB_OUTPUT_ITEMS-GTEXT.              BKPF-BELNR   =  ITAB_OUTPUT_ITEMS-BELNR.         
   SUBNO = SUBNO + 1.
   VSUBNO = SUBNO.
   DATAKBN = 2.
   VDATAKBN = DATAKBN.
   VGLT0-KSLVT = GLT0-KSLVT.
   VBIKKO = TGSBT-GTEXT.
   VBELNR = BKPF-BELNR.
   VSGTXT1 ='&#35531;&#27714;&#37329;&#38989;:'.
   CLEAR VRECORD.
  CONCATENATE  VSGTXT1 BSEG-SGTXT INTO VSGTXT.
  CONCATENATE VPAGENO VSUBNO VDATAKBN VCODE VNAME2 VPAYDAT VSGTXT
VGLT0-KSLVT VBIKKO VBELNR INTO VRECORD SEPARATED BY ','.
  TRANSFER VRECORD TO E_FILE.
   WRITE :/ VPAGENO,VSUBNO,VDATAKBN,'&#35531;&#27714;&#37329;&#38989;:', VSGTXT, VGLT0-KSLVT,
            VBIKKO,VBELNR.
  ENDLOOP.
  CLEAR: BSEG-SGTXT,GLT0-KSLVT,BKPF-BELNR.
LOOP AT ITAB_OUTPUT_ITEMS WHERE LIFNR = ITAB_LIFNR-LIFNR
                            AND   DTYPE = 6.          " &#21306;&#20998;&#65306;6
    BSEG-SGTXT   =  ITAB_OUTPUT_ITEMS-SGTXT.          " &#26126;&#32048;&#12486;&#12461;&#12473;&#12488;
    IF  ITAB_OUTPUT_ITEMS-SHKZG  =  CNS_CREDIT.       " &#37329;&#38989;
      GLT0-KSLVT  =  ITAB_OUTPUT_ITEMS-DMBTR * WK_RATIO.
    ELSEIF  ITAB_OUTPUT_ITEMS-SHKZG  =  CNS_DEBIT.
      GLT0-KSLVT  =  ITAB_OUTPUT_ITEMS-DMBTR * WK_RATIO * -1.
    ENDIF.
  TGSBT-GTEXT  =  ITAB_OUTPUT_ITEMS-GTEXT.          " &#20107;&#26989;&#38936;&#22495;&#12486;&#12461;&#12473;&#12488;
  BKPF-BELNR   =  ITAB_OUTPUT_ITEMS-BELNR.          " &#20253;&#31080;&#30058;&#21495;
  SUBNO = SUBNO + 1.
  VSUBNO = SUBNO.
  DATAKBN = 3.
  VDATAKBN = DATAKBN.
  VGLT0-KSLVT = GLT0-KSLVT.
  VBIKKO = TGSBT-GTEXT.
  VBELNR = BKPF-BELNR.
  VSGTXT1 ='&#30456;&#27578;&#37329;&#38989;:'.
  CLEAR VRECORD.
  CONCATENATE  VSGTXT1 BSEG-SGTXT INTO VSGTXT.
  CONCATENATE VPAGENO VSUBNO VDATAKBN VCODE VNAME2 VPAYDAT VSGTXT
  VGLT0-KSLVT VBIKKO VBELNR INTO VRECORD SEPARATED BY ','.
  TRANSFER VRECORD TO E_FILE.
concatenate vpageno vsubno vdatakbn
  WRITE :/ PAGENO,SUBNO,DATAKBN,'&#30456;&#27578;&#37329;&#38989;',BSEG-SGTXT, GLT0-KSLVT,
         TGSBT-GTEXT, BKPF-BELNR.
  ENDLOOP.
   CLEAR VRECORD.
*Insert empty line.
  TRANSFER EMPTYREC TO E_FILE.
  DATAKBN = 3.
  VDATAKBN = DATAKBN.
  SUBNO = SUBNO + 1.
  VSUBNO = SUBNO.
  VSGTXT ='&#28304;&#27849;&#37329;&#38989;'.
  VDMBTR = BSID-DMBTR.
  CONCATENATE VPAGENO VSUBNO VDATAKBN VCODE VNAME2 VPAYDAT VSGTXT
  VDMBTR INTO VRECORD SEPARATED BY ','.
  TRANSFER VRECORD TO E_FILE.
  WRITE :/ PAGENO, SUBNO,DATAKBN, ITAB_LIFNR-LIFNR,ITAB_LIFNR-NAME2,
         P_PAY_T,'&#28304;&#27849;&#37329;&#38989;', BSID-DMBTR.
  CLEAR: VDMBTR, VSGTXT, VRECORD.
  SUBNO = SUBNO + 1.
  VSUBNO = SUBNO.
  VSGTXT = '&#37109;&#36865;&#26009;'.
  VDMBTR = BSAD-DMBTR.
  CONCATENATE VPAGENO VSUBNO VDATAKBN VCODE VNAME2 VPAYDAT VSGTXT
  VDMBTR INTO VRECORD SEPARATED BY ','.
  TRANSFER VRECORD TO E_FILE.
  WRITE :/ PAGENO, SUBNO,DATAKBN,ITAB_LIFNR-LIFNR,ITAB_LIFNR-NAME2,
         P_PAY_T,'&#37109;&#36865;&#26009;', BSAD-DMBTR.
  CLEAR: VDMBTR, VSGTXT, VRECORD.
  SUBNO = SUBNO + 1.
  VSUBNO = SUBNO.
  VSGTXT = '&#25391;&#36796;&#12415;&#25163;&#25968;&#26009;'.
  VDMBTR = BSEG-DMBTR.
  CONCATENATE VPAGENO VSUBNO VDATAKBN VCODE VNAME2 VPAYDAT VSGTXT
  VDMBTR INTO VRECORD SEPARATED BY ','.
  TRANSFER VRECORD TO E_FILE.
  CLEAR: VDMBTR, VSGTXT, VRECORD.
  WRITE :/ PAGENO,SUBNO,DATAKBN,ITAB_LIFNR-LIFNR,ITAB_LIFNR-NAME2,
        P_PAY_T,'&#25391;&#36796;&#12415;&#25163;&#25968;&#26009;',BSEG-DMBTR.
*&#12381;&#12398;&#20182;&#12398;&#25903;&#25173;&#12356;&#12398;&#20966;&#29702;
  SUBNO = SUBNO + 1.
  VSUBNO = SUBNO.
  VSGTXT = '&#12381;&#12398;&#20182;&#12398;&#25903;&#25173;&#12356;'.
  VDMBTR = GLT0-TSL05.
  CONCATENATE VPAGENO VSUBNO VDATAKBN VCODE VNAME2 VPAYDAT VSGTXT
  VDMBTR INTO VRECORD SEPARATED BY ','.
  TRANSFER VRECORD TO E_FILE.
  WRITE :/ PAGENO,SUBNO,DATAKBN,ITAB_LIFNR-LIFNR,ITAB_LIFNR-NAME2,
        P_PAY_T, '&#12381;&#12398;&#20182;&#12398;&#25903;&#25173;&#12356;',GLT0-TSL05.
                                 glt0-tsl05.
ULINE.
CLEAR: VREC, VRECORD,VCODE,VNAME2,VPAYDAT,VSGTXT,VSGTXT1,VKINGAKU.
CLEAR: VBIKKO,VBELNR,VDMBTR,VGLT0-KSLVT,VGLT0-TSL01,VGLT0-TSL02.
CLEAR: VGLT0-TSL03,VGLT0-TSL04,VGLT0-TSL05,VKIN,VTEGA,VWK_PAY_AMOUNT.
ENDFORM.

Similar Messages

  • How to write new line to a File?

    How to write new line to a file?
    I have a string to be written to a file. the string contains "\n" in it. But why it is not showing the new line in the file.
    I have tryed FileWriter class and FileOutputStream class, but none of them works?
    any suggestion please...

    Probably using PrintStream::println() is a portable way.
    import java.io.FileOutputStream;
    import java.io.PrintStream;
    public class NewLine {
        public static void main(String[] args) {
         try {
             PrintStream ps = new PrintStream(new FileOutputStream("foo.txt"));
             ps.write("string".getBytes());
             ps.println();
             ps.close();
         } catch (java.io.IOException e) {
             e.printStackTrace();
    }Regards,

  • How to remove empty lines from xml files after removing nodes from document

    <pre>
    Hi
    <b>i have xml document, which is shown below
    after removing some nodes from the document ,i am getting empty lines in place of removed nodes,how to resolve this and get the proper xml document without any errors</b>
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <!DOCTYPE Message SYSTEM "TRD01.dtd">
    <Message>
    <Header>
    <CounterPartyType>CLIENT</CounterPartyType>
    <CreationTime>20134455</CreationTime>
    <ErrorCode>363 </ErrorCode>
    <ErrorEnterPriseId>N</ErrorEnterPriseId>
    <ErrorStatus>1</ErrorStatus>
    <ErrorSystemId>STL</ErrorSystemId>
    <ErrorTimes>31</ErrorTimes>
    <MessageType>T</MessageType>
    <RecipientEnterpriseId>N</RecipientEnterpriseId>
    <RecipentSystemId>EXM</RecipentSystemId>
    <Remarks>REMARSK</Remarks>
    <SenderEnterpriseId>N</SenderEnterpriseId>
    <SenderSystemId>TR</SenderSystemId>
    </Header>
    </Message>
    <ErrorCode>363 </ErrorCode>
    <ErrorEnterPriseId>NIHK</ErrorEnterPriseId>
    <ErrorStatus>1</ErrorStatus>
    <ErrorSystemId>STL</ErrorSystemId>
    <ErrorTimes>31</ErrorTimes>
    XPathExpression expression5 = xpath.compile(xmlpath5);
    Object result5 = expression5.evaluate(doc, XPathConstants.NODE);
    Node node5 = (Node) result5;
    node5.getParentNode().removeChild(node5);
    XPathExpression expression6 = xpath.compile(xmlpath6);
    Object result6 = expression6.evaluate(doc, XPathConstants.NODE);
    Node node6=(Node) result6;
    node6.getParentNode().removeChild(node6);
    XPathExpression expression7 = xpath.compile(xmlpath7);
    Object result7 = expression7.evaluate(doc, XPathConstants.NODE);
    Node node7=(Node) result7;
    node7.getParentNode().removeChild(node7);
    doc.normalize();
    doc.normalizeDocument();
    TransformerFactory tf = TransformerFactory.newInstance();
    Transformer t = tf.newTransformer();
    t.setOutputProperty(OutputKeys.INDENT, "yes");
    t.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
    t.setOutputProperty(OutputKeys.METHOD,"xml");
    t.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
    the xml output i am getting is
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <Message>
    <Header>
    <CounterPartyType>CLIENT</CounterPartyType>
    <CreationTime>20134455</CreationTime>
    <MessageType>TRD01</MessageType>
    <RecipientEnterpriseId>N</RecipientEnterpriseId>
    <RecipentSystemId>STL</RecipentSystemId>
    <Remarks>REMARSK</Remarks>
    <SenderEnterpriseId>N</SenderEnterpriseId>
    <SenderSystemId>T</SenderSystemId>
    </Header>
    </Message>
    <b>could you please let me know how to avoid empty lines in the xml doucment output</b>
    this is the method i am using to get the result
    public void ValidateRecord(String xml){
    try{
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = factory.newDocumentBuilder();
    //parse file into DOM
    /*DOMParser parser = new DOMParser();
    parser.setErrorStream(System.err);
    parser.setValidationMode(DTD_validation);
    parser.showWarnings(true);*/
    System.out.println ("HI THIS xml is validation "+xml);
    Resolver res = new Resolver();
    db.setEntityResolver(res);
    Document doc = db.parse(new InputSource(new StringReader(xml)));
    XPathFactory xpf = XPathFactory.newInstance();
    XPath xpath = xpf.newXPath();
    // XPathExpression expression = xpath.compile("//A/B[C/E/text()=13]");
    String xmlpath="/Message/Header/CounterPartyType/text()";
    String xmlpath1="/Message/Header/RecipentSystemId/text()";
    String xmlpath2="/Message/Header/ErrorSystemId/text()";
    XPathExpression expression = xpath.compile(xmlpath);
    XPathExpression expression1 = xpath.compile(xmlpath2);
    Object result = expression.evaluate(doc, XPathConstants.NODE);
    Object result1 = expression1.evaluate(doc, XPathConstants.NODE);
    Node node = (Node) result;
    Node node1 = (Node) result1;
    System.out.println("the values of the string is " +node.getNodeValue());
    System.out.println("the values of the string is " +node1.getNodeValue());
    // for (int i = 0; i < nodes.getLength(); i++) {
    //System.out.println(nodes.item(i).getNodeValue());
    // CAHNGING THE RECEIPENT NODE
    XPathExpression expression2 = xpath.compile(xmlpath1);
    Object result2 = expression2.evaluate(doc, XPathConstants.NODE);
    Node node2 = (Node) result2;
    System.out.println(node2);
    node2.setNodeValue(node1.getNodeValue());
    System.out.println(node2);
    //removing the nodes from document
    String xmlpath3="/Message/Header/ErrorCode";
    String xmlpath4="/Message/Header/ErrorEnterPriseId";
    String xmlpath5="/Message/Header/ErrorStatus";
    String xmlpath6="/Message/Header/ErrorSystemId";
    String xmlpath7="/Message/Header/ErrorTimes";
    XPathExpression expression3 = xpath.compile(xmlpath3);
    Object result3 = expression3.evaluate(doc, XPathConstants.NODE);
    Node node3 = (Node) result3;
    node3.getParentNode().removeChild(node3);
    XPathExpression expression4 = xpath.compile(xmlpath4);
    Object result4 = expression4.evaluate(doc, XPathConstants.NODE);
    Node node4 = (Node) result4;
    System.out.println("node value");
    System.out.println(node4.getParentNode().getNodeName());
    node4.getParentNode().removeChild(node4);
    XPathExpression expression5 = xpath.compile(xmlpath5);
    Object result5 = expression5.evaluate(doc, XPathConstants.NODE);
    Node node5 = (Node) result5;
    node5.getParentNode().removeChild(node5);
    XPathExpression expression6 = xpath.compile(xmlpath6);
    Object result6 = expression6.evaluate(doc, XPathConstants.NODE);
    Node node6=(Node) result6;
    node6.getParentNode().removeChild(node6);
    XPathExpression expression7 = xpath.compile(xmlpath7);
    Object result7 = expression7.evaluate(doc, XPathConstants.NODE);
    Node node7=(Node) result7;
    node7.getParentNode().removeChild(node7);
    // Node b13Node = (Node) expression.evaluate(doc, XPathConstants.NODE);
    //b13Node.getParentNode().removeChild(b13Node);
    doc.normalize();
    doc.normalizeDocument();
    TransformerFactory tf = TransformerFactory.newInstance();
    Transformer t = tf.newTransformer();
    t.setOutputProperty(OutputKeys.INDENT, "yes");
    t.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
    t.setOutputProperty(OutputKeys.METHOD,"xml");
    t.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
    t.transform(new DOMSource(doc), new StreamResult(System.out));
    catch (Exception e) {
         e.printStackTrace();
    System.out.println(e.getMessage());
    </pre>
    Edited by: user12185243 on Apr 6, 2013 6:38 AM
    Edited by: user12185243 on Apr 6, 2013 6:41 AM
    Edited by: user12185243 on Apr 6, 2013 6:43 AM
    Edited by: user12185243 on Apr 6, 2013 6:45 AM
    Edited by: user12185243 on Apr 6, 2013 9:00 AM

    either this way we can do this
    1)
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    <b> factory.setIgnoringElementContentWhitespace(true); </b>
    DocumentBuilder db = factory.newDocumentBuilder();
    or
    2)
    java.io.StringWriter sw = new java.io.StringWriter();
    StreamResult sr = new StreamResult(sw);
    t.transform(new DOMSource(doc), sr);
    String xml1 = sw.toString().trim();
    <b> xml1=xml1.replaceAll("\\s",""); </b>
    System.out.println(xml1.trim());

  • How to eliminate empty lines in Flat file.

    Hi All,
    How to delete the empty lines in flat file,i am explaining below with data
    Here we have 3 fields with field lengths 30,10,34  i am checking the condition in message mapping if the middle field containing 9999999999 i am deleting the total record but in output file i am getting empty line how to eleminate empy lines in file please suggest me is it possible through Content Convertion.
    Thanks,
    Sudheer.
    0500189175247200000500003141700000142888073108000009640566210000
    0500189175247200000500012449050000142889072908000009623017230000
    0500189175247200000500000496210000142890073008000009631840760000
    0500189175247200000500000162130000142891072808000009613028730000
    0500189175247200000500001356750000142892072908000009621443430000
    0500189175247200000500012982910000142893072908000009622158440000
    0500189175247200000500001380990000142894073008000009631876720000
    0500189175247200000500000074560000142895072808000009613904430000
    0500189175247200000500003351650000142896072908000009623005030000
    0500189175247200000500000061170000142898072808000009613026140000
    0500189175247200000500000060590000142900073008000009630862400000
    0500189175247200000500000155320000142901072908000009623234640000
    0500189175247200000500043425220000142903072808000009612752160000
    0500189175247200000500000517450000142904073108000009640911680000
    0500189175247200000500006901140000142905073008000009630927540000
    0500189175247200000500001565590000142906073008000009630938540000
    0500189175247200000500000210440000142907073108000009640765850000
    0500189175247200000500000187500000142908072908000009622980650000
    0500189175247200000500000069240000142909072908000009622980660000

    Hi,
    I think we could handle this with may be usage of Advanced UDF in Graphical mapping only.
    Here as per the condition you are deleting the particular record but unknowingly blank value i.e. " " is getting passed so on target side blank node is created for this record.
    You need to just avoid this blank Node.
    If you can share the logic you have applied for Middle field as well the source and target structure I will be able to try the UDF code..based on it
    Thanks
    swarup

  • How to replace a line ina text file using java?

    Hi ALL,
    Does anybody know how to replace a line in a text file uisng java.

    use this thing:
    http://doesthatevencompile.com/current-projects/code-sniplets/ASCIIFile.htm
    open the file,
    read its contents, replace the text you need in the contents, set the contents back into the file.
    it takes care of the IO for you.

  • How Can I replace line in text file

    I have a text file like following format
    1
    bvhhk
    g1
    2
    bvgjvh
    g1
    3
    mmm,mvb
    g2
    I want to replace 2 nd line to " prasad" and after replacing it should be following format
    1
    prasad
    g1
    2
    bvgjvh
    g1
    3
    mmm,mvb
    g2
    I try above change using following code segment and it is not work.
    static void modifyEmployeeDetails(String file_name){
    try{
         InputStreamReader reader= new InputStreamReader(System.in);
         BufferedReader buff=new BufferedReader(reader);
         FileReader read=new FileReader(file_name);
         BufferedReader buffer=new BufferedReader(read);
         FileWriter w=new FileWriter(file_name,true);
         PrintWriter write = new PrintWriter(w);
         System.out.print("Employee No : ");
         String No=buff.readLine();
    boolean eof = false;
    while (!eof) {
    String tep=buffer.readLine();
    if(tep.equals(No)){
    eof = true;
    System.out.print("Name : ");
    temp=buff.readLine();
    System.out.println("No");
    write.println(temp);
    System.out.print("Group No : ");
    temp=buff.readLine();
    write.println(temp);
    }catch(Exception e){
    System.out.println(e);
    Please correct If it is wrong and help me as soon as possible
    Thank you...............

    hi,
    I have a different approach of the solution to your problem.
    suppose you have entries in your file without any extra line feed between each two entries.
    the following program entirely reads your data into a bean list, changes a specific bean attribute and writes it to your data source.
    (you should adapt it to your needs)
    import java.io.BufferedReader;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.util.ArrayList;
    import java.util.List;
    public class FileReplace {
         public List<MyBean> readFile(BufferedReader in) throws IOException{
              String line;
              List<MyBean> beanList = new ArrayList<MyBean>();
              MyBean bean = null;
              int i=0;
              while((line=in.readLine())!=null){
                   if(line.trim().equals("***")){
                        beanList.add(bean);
                        i = 0;
                   }else{
                        switch (i) {
                        case 0:
                             bean = new MyBean();
                             bean.setAttribute1(line);
                             i++;
                             break;
                        case 1:
                             bean.setAttribute2(line);
                             i++;
                             break;
                        case 2:
                             bean.setAttribute3(line);
                             i++;
                             break;
                        default:
                             break;
              return beanList;
         public void writeToFile(List<MyBean> beanList, String outputFilePath) throws IOException{
              FileWriter out = new FileWriter(outputFilePath);
              for (int i = 0; i < beanList.size(); i++) {
                   out.write(beanList.get(i).toString());
              out.flush();
              out.close();
         public void test(){
              //BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
              String filePath = "D:/file.txt";
              try {
                   BufferedReader in = new BufferedReader(new FileReader(filePath));
                   //read data
                   List<MyBean> beanList = readFile(in);
                   // edit a bean attribute
                   beanList.get(0).setAttribute2("prasad");
                   //write beans back to file
                   writeToFile(beanList, filePath);
              } catch (FileNotFoundException e) {
                   e.printStackTrace(); //handle appropriately this exception
              } catch (IOException e) {
                   e.printStackTrace();//handle appropriately this exception
              }catch (Exception e) {
                   e.printStackTrace();//handle appropriately this exception
         class MyBean{
              String attribute1;
              String attribute2;
              String attribute3;
              public final static int ATTRS_NUMBER = 3;
              public String getAttribute1() {
                   return attribute1;
              public void setAttribute1(String attribute1) {
                   this.attribute1 = attribute1;
              public String getAttribute2() {
                   return attribute2;
              public void setAttribute2(String attribute2) {
                   this.attribute2 = attribute2;
              public String getAttribute3() {
                   return attribute3;
              public void setAttribute3(String attribute3) {
                   this.attribute3 = attribute3;
              @Override
              public String toString() {
                   return attribute1+"\n"+attribute2+"\n"+attribute3+"\n***\n";
         public static void main(String[] args) {
              FileReplace instance = new FileReplace();
              instance.test();
    }hope it helps

  • How to write new line on resource file.

    Hello Everyone,
    Can you please help me add new row on resource file, here is the code i have used to read my resource file.
    I have no idea on how to add new line... Please help 
    private void btnBrowse1_Click(object sender, EventArgs e)
    BrowseFile();
    //versionIncrement();
    if (txtInputfile.Text.Length > 0)
    PathSelection = txtInputfile.Text;
    oDataSet = new DataSet();
    //now am reading the files fro the path that is selected
    XmlReadMode omode = oDataSet.ReadXml(PathSelection);
    for (int i = 0; i < oDataSet.Tables[2].Rows.Count; i++)
    string comment = oDataSet.Tables["data"].Rows[i][2].ToString();
    //the elements array contain all the columns filled
    string[] elements = comment.Split('-'); //when it reaches the comma, it will jump to the next line
    string font = elements[0]; //Font
    string datestamp = elements[1]; //DateStamp
    string commentVal = elements[2]; //Comment
    string[] row = new string[] { oDataSet.Tables["data"].Rows[i][0].ToString(), oDataSet.Tables["data"].Rows[i][1].ToString(), font, datestamp = DateTime.Now.ToString(), commentVal };
    Gridview_Input.Rows.Add(row);

    Hello
    Sitholimela,
    >> Can you please help me add new row on resource file, here is the code i have used to read my resource file.
    From your description, it seems that your resource file is a XML format file, if so, you could also have a try to use
    LINQ To XML which is easy to operate the XML file to add new row to your resource file, and here is an example to show how to add a new element/row to the specific tree:
    Linq to XML Add element to specific sub tree
    Regards.
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • How to read long line from text file

    Hi,
    I just faced problem when reading a big text file.
    BufferedReader br = new BufferedReader(new FileReader("D:\\afile.txt"));
    String str;
    int i;
    while ((str = br.readLine())!=null)
    i++;
    //do some work here...
    ...This code throws exception:
    Exception in thread "main" java.lang.OutOfMemoryError: Java heap spaceSo I thought file line is very long. When I opened it in FAR it only displays no more than 4096 characters as a line.
    Help me to read a text file that's line is very long?

    try,
    $ java -X
    -Xmixed mixed mode execution (default)
    -Xint interpreted mode execution only
    -Xbootclasspath:<directories and zip/jar files separated by ;>
    set search path for bootstrap classes and resources
    -Xbootclasspath/a:<directories and zip/jar files separated by ;>
    append to end of bootstrap class path
    -Xbootclasspath/p:<directories and zip/jar files separated by ;>
    prepend in front of bootstrap class path
    -Xnoclassgc disable class garbage collection
    -Xincgc enable incremental garbage collection
    -Xloggc:<file> log GC status to a file with time stamps
    -Xbatch disable background compilation
    -Xms<size> set initial Java heap size
    -Xmx<size> set maximum Java heap size
    -Xss<size> set java thread stack size
    -Xprof output cpu profiling data
    -Xrunhprof[:help]|[:<option>=<value>, ...]
    perform JVMPI heap, cpu, or monitor profiling
    -Xdebug enable remote debugging
    -Xfuture enable strictest checks, anticipating future default
    -Xrs reduce use of OS signals by Java/VM (see documentation)
    -Xcheck:jni perform additional checks for JNI functions
    The -X options are non-standard and subject to change without notice.

  • How to write Strings in a text file with BufferedWriter

    I've got a Vector object full of Strings objects, I'm interested in wrinting these Strings in a text file with a BufferedWriter , I would apreciate some code, thank you

    http://java.sun.com/products/jdk/1.2/docs/api/java/io/BufferedWriter.html
    "PrintWriter out = new PrintWriter(new BufferedWriter((new FileWriter("foo.out")));"

  • How to know a line of text file is ending with line feed or return?

    hi all, i have a program that read log file that generated by other service (apache http server for example), i want to know that each line is ending with "\r", "\n" or "\r\n" so i can skip them in the next time, like this:
    int char_counter=0;
    BufferedReader reader = new BufferedReader(new FileReader(logFileName));
    while((line=reader.readLine())!=null){
           char_counter+=line.length()+x_value;
    }and the next time read the log file, i will skip all the lines that read in previous time.
    BufferedReader reader = new BufferedReader(new FileReader(logFileName));
    reader.skip(char_counter);
    while((line=reader.readLine())!=null){
           char_counter+=line.length()+x_value;
    }with x_value is 1 or 2 depended on line end with "\n" or "\r\n".
    so, how to know which is the char line ending with?
    Edited by: secmask on Feb 21, 2009 5:46 AM

    Alright, the BufferedReader method readLine() reads all text until it finds a \n character. And then next time you call it it will automatically continue from where it left out.
    try this out it should show it as an example
    import java.io.*;
    public class readLineTest {
        static FileOutputStream filename;
        static BufferedReader input;
        public static void main(String[] args)
            try
                filename = new FileOutputStream("logFile.txt", false);
            catch (IOException e)
                //blank
            PrintStream output = new PrintStream(filename);
            output.println("this is the first line");
            output.println("this is the second line");
            output.println("this is the third line");
            try
                input = new BufferedReader(new FileReader("logFile.txt"));
            catch(IOException e)
                //blank
            for(int i = 0; i < 3; i++)
                try
                    System.out.println(input.readLine());
                catch(IOException e)
                    //blank
    }

  • How to write from beginning of text file?

    Hello all,
    All we have to do is to modify just first 2 lines of a 200,000 line files. I can do UTL_FILE.FCOPY to copy from line 3 to end of file and create a new file (FILE1). Now open a new file (say FILE2) and write the modified version of first two lines and then read the file (FILE1) which has rest of the original contents to write to this FILE2. But this process is taking for ever (around 30 minutes).
    It would have been easy if I can open FILE1 and just write the first 2 lines. But when I open in append mode I can only write only at the bottom of the file. I tried UTL_FILE.FSEEK but it is not working when the file is opened in Append mode.
    Anyone with a solution / suggestion / workaround is greatly appreciated.
    Thanks in advance,
    Manohar

    Francois,
    I know the command in Unix to concatenate. There are other easy ways if I can make HOST command work on the application server instead of my local machine. To my surprise both HOST and TEXT_IO are able to work only on my local machine.
    I was under the same impression as you are and trying to execute HOST providing Unix commands. Nothing working ... finally when I tried
    HOST('echo abc > c:\sample.txt');
    it crreated sample.txt on my local machine c:\
    Let me know if I am missing something.
    Thanks
    Manohar

  • How to write/insert lines in a file from top

    I am opening a writing to a file as follows:
    (part of the code which does so)
    FileOutputStream file; // declare a file output object
    PrintStream r;
    file = new FileOutputStream("filename") + ".properties",true);
    r = new PrintStream( raj);
    r.println ( value + "=" + data.getString(value) );
    r.close();
    This prints in file line after line like
    A
    B
    C
    How can I make it to print/insert new line right at the top ?
    That is if I print A, then B, then C, how can I make it to get
    C
    B
    A
    in the file ?
    Help is much appriciated.

    Use a RandomAccessFile then you can position the
    cursor anywhere in the file.Yes, but that still doesn't allow data to be inserted unless all following data is shifted to make room for the insertion. (If you don't shift, the inserted data will overwrite following data already there.)

  • How copy just line in text file with cat? (SOLVED)

    Hi.
    How i make to copy just only line in text file with cat?
    For example:
    [:0.0]
    file=/home/Arch/./.wallpaper.png
    mode=0
    bgcolor=# 0 0 0
    I want copy just "/home/Arch/./.wallpaper.png" part.
    Actually i want create a shortcut for last wallpaper set from Nitroget, then i put this in SLim background.
    Recently i use hsetroot for wallpaper (~/.wallpaper.png) and i create a shortcut in /usr/share/slim/theme/MYTHEME whith ln -s ~/.wallpaper.png /usr/share/slim/theme/MYTHEME/background.png.
    I want make a same with Nitrogen.
    I now this looks like crazy, but...
    Sorry my English.
    Last edited by kramerxiita (2008-06-04 16:50:48)

    moljac024 wrote:
    kramerxiita wrote:
    moljac024 wrote:How can you make SliM change the background ? You link the theme background to another file ?
    Yes. In theme directory i put background.png shortcut for my wallpaper. So, when a change wallpaper, slim background change too.
    Example:
    ln -s mywallpaper.png /usr/share/slim/themes/default/background.png
    So, Slim background always is my wallpaper.
    So the wallpaper has to be a *.png ?
    No, jpg is possible. But when you create a symbolic link, remember put the extension too. If change png to jpg, change a symbolic link extension.
    But, remember if slim theme directory have background.png and background.jpg, Slim always choice .png. So, put only one this.

  • How to get the content of text file to write in JTextArea?

    Hello,
    I have text area and File chooser..
    i wanna the content of choosed file to be written into text area..
    I have this code:
    import java.awt.Container;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.io.File;
    import javax.swing.JButton;
    import javax.swing.JFileChooser;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.*;
    public class Test_Stemmer extends JFrame {
    public Test_Stemmer() {
    super("Arabic Stemmer..");
    setSize(350, 470);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setResizable(false);
    Container c = getContentPane();
    c.setLayout(new FlowLayout());
    JButton openButton = new JButton("Open");
    JButton saveButton = new JButton("Save");
    JButton dirButton = new JButton("Pick Dir");
    JTextArea ta=new JTextArea("File will be written here", 10, 25);
    JTextArea ta2=new JTextArea("Stemmed File will be written here", 10, 25);
    final JLabel statusbar =
                  new JLabel("Output of your selection will go here");
    // Create a file chooser that opens up as an Open dialog
    openButton.addActionListener(new ActionListener() {
       public void actionPerformed(ActionEvent ae) {
         JFileChooser chooser = new JFileChooser();
         chooser.setMultiSelectionEnabled(true);
         int option = chooser.showOpenDialog(Test_Stemmer.this);
         if (option == JFileChooser.APPROVE_OPTION) {
           File[] sf = chooser.getSelectedFiles();
           String filelist = "nothing";
           if (sf.length > 0) filelist = sf[0].getName();
           for (int i = 1; i < sf.length; i++) {
             filelist += ", " + sf.getName();
    statusbar.setText("You chose " + filelist);
    else {
    statusbar.setText("You canceled.");
    // Create a file chooser that opens up as a Save dialog
    saveButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent ae) {
    JFileChooser chooser = new JFileChooser();
    int option = chooser.showSaveDialog(Test_Stemmer.this);
    if (option == JFileChooser.APPROVE_OPTION) {
    statusbar.setText("You saved " + ((chooser.getSelectedFile()!=null)?
    chooser.getSelectedFile().getName():"nothing"));
    else {
    statusbar.setText("You canceled.");
    // Create a file chooser that allows you to pick a directory
    // rather than a file
    dirButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent ae) {
    JFileChooser chooser = new JFileChooser();
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    int option = chooser.showOpenDialog(Test_Stemmer.this);
    if (option == JFileChooser.APPROVE_OPTION) {
    statusbar.setText("You opened " + ((chooser.getSelectedFile()!=null)?
    chooser.getSelectedFile().getName():"nothing"));
    else {
    statusbar.setText("You canceled.");
    c.add(openButton);
    c.add(saveButton);
    c.add(dirButton);
    c.add(statusbar);
    c.add(ta);
    c.add(ta2);
    public static void main(String args[]) {
    Test_Stemmer sfc = new Test_Stemmer();
    sfc.setVisible(true);
    }could you please help me, and tell me what to add or to modify,,
    Thank you..                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    realahmed8 wrote:
    thanks masijade,
    i have filter the file chooser for only text files,
    but i still don't know how to use FileReader to put text file content to the text area (ta) ..
    please tell me how and where to use it..How? -- See the IO Tutorials on Sun for the FileReader (and I assume you know how to call setText and append in the JTextArea).
    Where? -- In the actionPerformed method (better would be a separate thread that is triggered through the actionPerformed method, but that is probably beyond you at the moment), of course.
    Give it a try.

  • How to write data to an XML file present under application server

    frnds: can ne one tell me, how to write data in to a file, which is present under a application server
    Ex: i want to write a string data in to a file test.txt which is present under "http://localhost:8080/<some_webapp>/test.txt"
    Note:i have deploted a service<some_webapp> under Tomcat/webapps dir

    Very simple. A servlet can writes to that file if it has the good rights.
    In the servlet get (or post) method, use a code like this:
    import java.io.*;
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
    try {
    String filePath = this.getServletContext().getRealPath("/text.txt");//See http://java.sun.com/products/servlet/2.2/javadoc/javax/servlet/ServletContext.html#getRealPath(java.lang.String)
             PrintWriter writer = new PrintWriter (filePath);
            //or BufferedWriter out = new BufferedWriter(new FileWriter(filePath));
            writer .println("aString");
           writer.flush();
            writer .close();
        } catch (Exception e) {
           e.printStackTrace();
    }Hope That Helps

Maybe you are looking for

  • Library Tables in Report Painter ?

    Hello, can we use two tables while creating a library for the report painter ?  mmy guess is on using a view ?? If views, then how to use them in the libray while defining the characteristics n all ?? Hope i am comprehendable .. Thanks. Shehryar

  • R/3 to XI- IDOC posting

    I am sending the standard Idoc ORDERS from R/3 to XI.When I post the IDOC from transaction WE19. It shows that IDOC is sucessfully sent and saved. but when i check the message in XI by I enter Message ID: ORDERS, I am getting this popup "No message s

  • Create a form for viewers to submit by email

    I have a registration form that viewers can register for a class, how do I make it so they can select or input the information and then hit the submit button and it will e-mail me the form? Here is the link... http://www.relevanceonline.org/AlphaRegi

  • What is the use of sqlplus /nolog?

    What is the use of sqlplus /nolog?

  • JMeter - Can I load a script?

    Hi to all, I have a sequence of istruction in some java classes. How I can run them with JMeter? Is it possible? Can I upload a file (f.e. a jar file) where JMeter understand what I want to do?