Exeption  - trying to write to file, using CSVWriter.

I have got the following exception:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at application.utils.GestureGuideLogger.logExcel(GestureGuideLogger.java
:238)
the row code is:
     238:     writerExcel.writeNext(new String[]{buffer.toString()});
same happens, if I write instead:
          writerExcel.writeNext(messageExcel);
//messageExcel is "String[]" as well.
What is wrong?
Thanks!

What is wrong?Well, you get a NullPointerException. That means only one thing: you try to call a method on an object reference that is null.
Check the line, there are two objects that can be null at that point.
- writerExcel
- buffer
I'm betting that buffer contains null.

Similar Messages

  • How to write a file using mod pl/sql

    hi,
    i am having a submit button in my procedure. which should inturn create .sql file in a file path.
    is there any way to create a fileusing htp and htf methods.
    Thanks in advance
    Hari

    >
    i am having a submit button in my procedure. which should in turn create .sql file in a file path.
    is there any way to create a file using htp and htf methods.
    >
    Why are you wasting your time coding from scratch using the PL/SQL Web Toolkit instead of the APEX framework?
    From Re: how to write a file using mod pl/sql it appears that you are not using APEX, so a number of the approaches APEX offers are not relevant. You appear to be looking for a file download solution using the <tt>wpg_docload.download_file</tt> method, such as:
    create or replace procedure download_file (
        p_filename  in     varchar2
      , p_mimetype  in     varchar2
      , p_content   in out nocopy blob)
    is
    begin
      -- Set up HTTP header.
      -- Use "application/octet" as default MIME type.
      owa_util.mime_header(nvl(p_mimetype, 'application/octet'), false);
      -- Set the size so the browser knows how much to download.
      htp.p('Content-length: ' || dbms_lob.getlength(p_content));
      -- Filename will be used as default by the browser in "Save as..."
      htp.p('Content-Disposition: attachment; filename="' || p_filename || '"');
      -- Close header.
      owa_util.http_header_close();
      -- Stream the file content to the browser.
      wpg_docload.download_file(p_content);
    end download_file;

  • Beginner question - Can't read nor write a file using NetBean...

    Hi ,
    I'm a beginner java programmer, I got trouble when it comes to read or write a file program..
    I tried 3 programs and all of them can't read the file I want to read, eventhought I have put the txt file in the same folder with my source code.
    here is the source code I got from some site
    import java.io.*;
    class FileReadTest {
    public static void main (String[] args) {
         FileReadTest f = new FileReadTest();
    f.readMyFile();
    void readMyFile() {
    DataInputStream dis = null;
    String record = null;
    int recCount = 0;
    try {
    File f = new File("mydata.txt");
    FileInputStream fis = new FileInputStream(f);
    BufferedInputStream bis = new BufferedInputStream(fis);
    dis = new DataInputStream(bis);
    while ( (record=dis.readLine()) != null ) {
    recCount++;
    System.out.println(recCount + ": " + record);
    } catch (IOException e) {
    // catch io errors from FileInputStream or readLine()
    System.out.println("Uh oh, got an IOException error! " + e.getMessage());
    } finally {
    // if the file opened okay, make sure we close it
    if (dis != null) {
         try {
    dis.close();
         } catch (IOException ioe) {
    I also have tried another from book , both of them give the same result, can't read the file...
    Please help me with this...
    Thank you very much

    To start with use the full path to the file
    i.e. File f = new File("c:\\the\\full\\path\\to\\your\\file\\mydata.txt"); // Assumes a Windows platform using the C drive
    Then check to make sure you fiel exists e.g. System.out.println("File exists = " + f.exists());
    You can even test to see if the file is readable but since you created the file this porbably is not required.

  • Exception while trying to write xml file

    When I try to write my DOM tree to an XML file a get the following exception form the transformer.transform() function call:
    Exception in thread "AWT-EventQueue-0" java.lang.AbstractMethodError: org.apache.crimson.tree.XmlDocument.getXmlStandalone()Z
    at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.setDocumentInfo(DOM2TO.java:373)
    at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(DOM2TO.java:127)
    at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(DOM2TO.java:94)
    at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transformIdentity(TransformerImpl.java:662)
    at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:708)
    at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:313)
    at CentMon.ConfigRW.writeConfig(ConfigRW.java:77)
    The whole thing worked for 2 years. I did not change anything on the code. the only difference is that i have now office 2007 installed instead of office 2003.
    That's the code which generates the exception:
    import java.io.File;
    import java.io.IOException;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.ParserConfigurationException;
    import javax.xml.transform.Transformer;
    import javax.xml.transform.TransformerConfigurationException;
    import javax.xml.transform.TransformerException;
    import javax.xml.transform.TransformerFactory;
    import javax.xml.transform.dom.DOMSource;
    import javax.xml.transform.stream.StreamResult;
    import org.w3c.dom.Document;
    import org.xml.sax.SAXException;
    public void writeConfig(Document doc){
    TransformerFactory tFactory =
    TransformerFactory.newInstance();
    Transformer transformer;
    if (doc==null){
    System.out.println("Document is null");
    else{
    try {
    transformer = tFactory.newTransformer();
    } catch (TransformerConfigurationException e) {
    transformer = null;
    System.out.println(e.getMessage());
    DOMSource source = new DOMSource(doc);
    StreamResult result = new StreamResult(new File(filename));
    try {
    if (transformer != null){
    transformer.transform(source, result);
    } catch (TransformerException ex) {
    Logger.getLogger(ConfigRW.class.getName()).log(Level.SEVERE, null, ex);
    }

    I am getting the exact same error when trying to write out an XML file. I have been following the J2EE Tutorial. Perhaps I need to look for a more recent tutorial.
    Exception in thread "AWT-EventQueue-0" java.lang.AbstractMethodError: org.apache.crimson.tree.XmlDocument.getXmlStandalone()Z
    at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.setDocumentInfo(DOM2TO.java:373)
    at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(DOM2TO.java:127)
    at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(DOM2TO.java:94)
    at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transformIdentity(TransformerImpl.java:662)
    at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:708)
    at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:313)
    at com.wordhopper.xml.DOMXMLParser.writeXMLFile(DOMXMLParser.java:55)
    at com.wordhopper.gui.xmltool.XMLEditor.writeButtonActionPerformed(XMLEditor.java:217)
    at com.wordhopper.gui.xmltool.XMLEditor.access$100(XMLEditor.java:13)
    at com.wordhopper.gui.xmltool.XMLEditor$2.actionPerformed(XMLEditor.java:139)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2028)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2351)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
    at java.awt.Component.processMouseEvent(Component.java:6348)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
    at java.awt.Component.processEvent(Component.java:6113)
    at java.awt.Container.processEvent(Container.java:2085)
    at java.awt.Component.dispatchEventImpl(Component.java:4714)
    at java.awt.Container.dispatchEventImpl(Container.java:2143)
    at java.awt.Component.dispatchEvent(Component.java:4544)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4618)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4282)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4212)
    at java.awt.Container.dispatchEventImpl(Container.java:2129)
    at java.awt.Window.dispatchEventImpl(Window.java:2475)
    at java.awt.Component.dispatchEvent(Component.java:4544)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:635)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

  • Trying to export xml file using tcExportOperationsIntf

    Hi All,
    I am trying to export the xml files using tcExportOperationsIntf in OIM 10g. But I am getting the null pointer exception while finding the objects using findObjects method
    FileWriter fstream = new FileWriter("OIMResources.xml");
            BufferedWriter out = new BufferedWriter(fstream);
      tcExportOperationsIntf  xlexportOper = (tcExportOperationsIntf)tc.getUtility("Thor.API.Operations.tcExportOperationsIntf");
      System.out.println("Before export..1");
      Collection<RootObject>lstObjects = (List)xlexportOper.findObjects("Resource", "AD User");
            System.out.println(lstObjects);
    Error:
    java.lang.NullPointerException
            at Thor.API.Operations.tcExportOperationsClient.findObjects(Unknown Sour
    ce)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
    java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
    sorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:324)
            at Thor.API.Base.SecurityInvocationHandler$1.run(Unknown Source)
            at Thor.API.Security.LoginHandler.jbossLoginSession.runAs(Unknown Source
            at Thor.API.Base.SecurityInvocationHandler.invoke(Unknown Source)
            at $Proxy5.findObjects(Unknown Source)
            at ExportFile.create(ExportFile.java:32)
            at ExportFile.main(ExportFile.java:16)
    Can any one tell me where I did the mistake.
    Thanks
    K

    Try this:
       tcExportOperationsIntf  exportIntf = oimClient
         .getService(tcExportOperationsIntf .class);
       Collection roots = exportIntf.findObjects("Resource", "AD User");
       //Export Selected Objects
       String xml = exportIntf.getExportXML(roots, "AD User");
       System.out.println(xml);

  • HT4284 We are trying to open .mov files using Quick Time. It says that it is unable to open it because a codec is not available.  What do we need to do?

    We are trying to open and edit .mov files using Quick Time. It says that it is unable to open it because a codec is not available. What do we need to do?

    he knows his ID , if he did all whats in the link he can get his password back ?
    how can i make him call applecare ? is there a way to speak to them from jordan ??
    i have been trying to reach any1 in apple so they can communicate and help my friend (us) to make him remember it .
    am not asking for the password or trying to get into the phone without using it , and i can take my money back though i need to help my friend as well since now he cant use it as well.
    thanks kil

  • Read&write Excel file using java

    Hi everybody,
    I have an assignment about methods that read and write an excel file using java (Eclipse SDK), so if anyone know about that please post the solution as soon as possible.
    Thanks
    Sendbad

    http://onesearch.sun.com/search/onesearch/index.jsp?qt=read+write+excel&subCat=siteforumid%3Ajava31&site=dev&dftab=siteforumid%3Ajava31&chooseCat=javaall&col=developer-forums

  • I tried to open a file using reader 10. Now reader has taken over all my apps including explorer and live mail and nothing will open unless I uninstall reader. System is windows 7. How can I reverse this?

    I was trying to open a file, the box came up saying that windows could not open the file and choose another program to open the file, I chose reader as it was the first option offered. Reader could not open the file either but when I closed the file I fount that nearly all the desktop  icons had changed to reader icons and when I tried to open them a box comes up advising that reader cannot open that file. The only way that I can open my apps is to uninstall reader. When I uninstall reader the Icons return to normal. As soon as I re install reader all my icons change back to reader icons. How can I reverse this?

    See http://helpx.adobe.com/acrobat/kb/application-file-icons-change-acrobat.html

  • Getting ORA-22805 when trying to load XML file using SQLLDR

    I'm trying to learn the basics of XML since we'll be getting XML files in the near future. I'm using one of the sample schemas that comes with XMLSPY. I loaded this schema into an 11g Oracle DB using XMLSPY:
    <?xml version="1.0" encoding="UTF-8"?>
    <!-- edited with XML Spy v4.0 NT beta 1 build Jun 13 2001 (http://www.xmlspy.com) by Alexander Falk (Altova, Inc.) -->
    <schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:ipo="http://www.altova.com/IPO" targetNamespace="http://www.altova.com/IPO" elementFormDefault="unqualified" attributeFormDefault="unqualified">
         <annotation>
              <documentation>
    International Purchase order schema for Example.com
    Copyright 2000 Example.com. All rights reserved.
    </documentation>
         </annotation>
         <!-- include address constructs -->
         <include schemaLocation="address.xsd"/>
         <element name="purchaseOrder" type="ipo:PurchaseOrderType"/>
         <element name="comment" type="string"/>
         <complexType name="PurchaseOrderType">
              <sequence>
                   <element name="shipTo" type="ipo:Address"/>
                   <element name="billTo" type="ipo:Address"/>
                   <element ref="ipo:comment" minOccurs="0"/>
                   <element name="Items" type="ipo:Items"/>
              </sequence>
              <attribute name="orderDate" type="date"/>
         </complexType>
         <complexType name="Items">
              <sequence>
                   <element name="item" minOccurs="0" maxOccurs="unbounded">
                        <complexType>
                             <sequence>
                                  <element name="productName" type="string"/>
                                  <element name="quantity">
                                       <simpleType>
                                            <restriction base="positiveInteger">
                                                 <maxExclusive value="100"/>
                                            </restriction>
                                       </simpleType>
                                  </element>
                                  <element name="price" type="decimal"/>
                                  <element ref="ipo:comment" minOccurs="0"/>
                                  <element name="shipDate" type="date" minOccurs="0"/>
                             </sequence>
                             <attribute name="partNum" type="ipo:Sku"/>
                        </complexType>
                   </element>
              </sequence>
         </complexType>
         <simpleType name="Sku">
              <restriction base="string">
                   <pattern value="\d{3}-[A-Z]{2}"/>
              </restriction>
         </simpleType>
    </schema>
    Then I created an XMLType table:
    CREATE TABLE purchaseOrder OF XMLType
    XMLSCHEMA "ipo.xsd" ELEMENT "purchaseOrder"
    I'm trying to load the sample XML file ipo.xml into purchaseOrder using SQLLDR. This is ipo.xml:
    <?xml version="1.0"?>
    <!-- edited with XMLSPY v2004 rel. 4 U (http://www.xmlspy.com) by Mr. Nobody (Altova GmbH) -->
    <ipo:purchaseOrder xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ipo="http://www.altova.com/IPO" orderDate="1999-12-01" xsi:schemaLocation="http://www.altova.com/IPO
    ipo.xsd">
         <shipTo export-code="1" xsi:type="ipo:EU-Address">
              <ipo:name>Helen Zoe</ipo:name>
              <ipo:street>47 Eden Street</ipo:street>
              <ipo:city>Cambridge</ipo:city>
              <ipo:postcode>126</ipo:postcode>
         </shipTo>
         <billTo xsi:type="ipo:US-Address">
              <ipo:name>Robert Smith</ipo:name>
              <ipo:street>8 Oak Avenue</ipo:street>
              <ipo:city>Old Town</ipo:city>
              <ipo:state>AK</ipo:state>
              <ipo:zip>95819</ipo:zip>
         </billTo>
         <Items>
              <item partNum="833-AA">
                   <productName>Lapis necklace</productName>
                   <quantity>2</quantity>
                   <price>99.95</price>
                   <ipo:comment>Need this for the holidays!</ipo:comment>
                   <shipDate>1999-12-05</shipDate>
              </item>
              <item partNum="748-OT">
                   <productName>Diamond heart</productName>
                   <quantity>1</quantity>
                   <price>248.90</price>
                   <ipo:comment>Valentine's day packaging.</ipo:comment>
                   <shipDate>2000-02-14</shipDate>
              </item>
              <item partNum="783-KL">
                   <productName>Uncut diamond</productName>
                   <quantity>7</quantity>
                   <price>79.90</price>
                   <shipDate>2000-01-07</shipDate>
              </item>
              <item partNum="238-KK">
                   <productName>Amber ring</productName>
                   <quantity>3</quantity>
                   <price>89.90</price>
                   <ipo:comment>With no inclusions, please.</ipo:comment>
                   <shipDate>2000-01-07</shipDate>
              </item>
              <item partNum="229-OB">
                   <productName>Pearl necklace</productName>
                   <quantity>1</quantity>
                   <price>4879.00</price>
                   <shipDate>1999-12-05</shipDate>
              </item>
              <item partNum="128-UL">
                   <productName>Jade earring</productName>
                   <quantity>5</quantity>
                   <price>179.90</price>
                   <shipDate>2000-02-14</shipDate>
              </item>
         </Items>
    </ipo:purchaseOrder>
    This is what's in the control file:
    LOAD DATA
    INFILE *
    INTO TABLE purchaseOrder TRUNCATE
    xmltype(xmldata)
    FIELDS
    xmldata LOBFILE (CONSTANT ipo.xml)
    BEGINDATA
    0
    The load fails with:
    Record 1: Rejected - Error on table PURCHASEORDER.
    ORA-22805: cannot insert NULL object into object tables or nested tables
    Another question I have is, how do we know how many records (0's) to specify in the control file? In this case there's only one but when real files are used we won't know how many are in the file.
    Thanks for your help!

    The concept was "Don't use SQL*Loader to parse XML".
    You can use SQL*Loader to load an entire XML document into the DB. That is fine. You can do the same via BFILENAME to read in files from disk as well.
    If you want to parse XML, do that from within Oracle via PL/SQL and/or SQL. The solution depends upon your version of Oracle and what is good enough for you in terms of performance.
    So the basics are
    a) How am I getting the information?
    b) How am I getting in into Oracle?
    c) How do I want to parse it?
    As I see the schema, it only allows for one ipo:purchaseOrder node in the document, since that is the root node. If you have multiple in the incoming file, you no longer have valid XML, both per the schema and because you have no single root node. You have an XML fragment, which must be treated different.
    Just trying to understand the question since I now realize it does not agree with what the schema in your initial example shows.

  • Any way to avoid 'save as' dialog/pop-up when trying to save some file using flex?

    I am trying to create an image file with flex and want to save it only in�� a perticular directory ie., user should not be given any option to choose the location.Air application uses resolvePath where we can specify the path but donno how this can be achieved for a web-based application.
    Is there any workaround for this?

    I am trying to create an image file with flex and want to save it only in  a perticular directory ie., user should not be given any option to choose the location.Air application uses resolvePath where we can specify the path but donno how this can be achieved for a web-based application.
    Is there any workaround for this?
    Thanks.

  • Error trying to open a file using java.io.* in an Applet

    I have a file called wordlist.txt and I am using java.io.* to open it. When I try it
    in Applet Viewer it runs without a hitch. But when I try to run it in a
    browser as an Applet, it errors out saying:
    com.ms.security.SecurityExceptionEx[package3/SpellCheck.setWordList]: cannot access file wordlist.txt
    I have tried adding this file to my Project and accessing it that way but I still get
    the same message. If anyone can help with this, I sure would appreciate it.
    My code is as follows:
    String inWord = new String("zzz");
    try {
    File myWordList = new File("wordlist.txt");
    BufferedReader inWordList = new BufferedReader(
    new FileReader(myWordList));
    inWord = inWordList.readLine();
    while (inWord != null) {
    wordList.addElement(inWord);
    inWord = inWordList.readLine();
    } // end while
    inWordList.close();
    } // end try
    catch (Exception e1) {
    // Pr is equivalent System.out.println();
    Pr("Error Reading this line " + '\n' + inWord + '\n' + e1);
    } // end catch
    } // end setWordList()

    Applets are generally prevented from reading as well as writing files, but appletviewer can load files from the hard drive, so, that is the cause of the behaviour you have observed. To know more about enabling applets load files, you have to sign your applets,
    learn more at
    http://java.sun.com/sfaq/#prevent

  • Setting a loop to write a file using the UTL_FILE

    I never done this using the UTL file, so I am going to ask, I need to create a file that is looks like this
    H xxxxxxxxxxxx (the header same for the all file)
    I Invoice Data (Information on Each account Number)
    D (invoice Dtail) Detail information in each account
    D
    D
    D
    I  Invoice Data (Information on Each account Number (record 2 ) diferrent Account #n )
    D (invoice Dtail) Detail information on account2
    D
    D
    D
    I  Invoice Data (Information on Each account Number (record 3 ) diferrent Account #n )
    D (invoice Dtail) Detail information on account3
    D
    D
    D
    File Footer
    Number on invoices
    And totals I have the H the header the I (invoice Data) and D (detail) in cursors
    I wonder how I can set up the loop, so the information will ended
    like
    The heade on top of the file, not problem here
    but each
    I Invoice Data
    needs to have the respectively
    D detail lines
    I hope this is clear!!

    If cursors x, y, and z map to H, I, and D in your file spec, you would need to nest the D cursor within the I cursor
    FOR   x in  Invoice_data_cur
       LOOP
             utl_file.put_line(outfile,
               RPAD ('I', 2, ' ')
             ||RPAD (x.spriden_id, 9)
             ||TO_CHAR (SYSDATE, 'MM/DD/RRRR')
             ||RPAD (x.balance1, 13, '0')
               ---more stuff
       FOR  y in invoice_detail_charges_cur(x.pidm) 
             LOOP
                 utl_file.put_line( outfile,
                  RPAD ('D', 2, ' ')
                ||RPAD (y.spriden_id, 9)
                ||RPAD ('Previous Balance', 16, ' ')
                ||RPAD (y.stvterm_desc, 9, ' ')
                ||RPAD (TO_CHAR (SYSDATE, 'MM/DD/RRRR'), 10)
                ||RPAD (y.tbbdetc_desc, 50, ' ')
                ||LPAD(NVL (y.tbraccd_amount, '0000000000000'), 13, '0')
           for z in invoice_detail_payments_cur(x.pidm)
              LOOP
                   utl_file.put_line( outfile,
                    RPAD ('D', 2, ' ')
                  ||RPAD (z.spriden_id, 9)
                  ||RPAD ('Pending Aid ', 16, ' ')
                  ||RPAD (z.STVTERM_DESC, 9, ' ')
                  ||RPAD (TO_CHAR (SYSDATE, 'MM/DD/RRRR'), 10)
                  ||RPAD (z.tbbdetc_desc, 50, ' ')
                  ||LPAD (NVL (z.tbraccd_amount, '0000000000000'), 13, '0')
              END LOOP;      
            END LOOP;
    END LOOP;From a code clarity standpoint, if your file spec uses H, I, and D as a sort of row-type identifier, I would strongly suggest that your loop variable follow that convention or spell out the row type. That is
    FOR h IN Invoice_data_cur
    LOOP
      <<write header>>
      FOR i IN invoice_detail_charges_cur(h.pidm)
      LOOP
        <<write invoice data>>
        FOR d IN invoice_detail_payments_cur( h.pidm )
        LOOP
          <<write invoice detail>>
        END LOOP;
      END LOOP;
    END LOOP;Justin

  • How to write to file using fixed width columns

    I need to write some data to a text file such that it is formatted in columns of fixed width. Each column can have different width. eg if i have to write 5 fields in each record the first field would be of 5 characters, second field of 3 characters and so on.
    Can u please suggest how I can do it. Its urgent.

    Can't you search? Now you know what to google on: java 5 printf
    Kaj

  • Possible to read/ write word files using Java?

    I'm planning to write a Java application that can read an MS word document, extract something (including mathematics equations created with the equation editor) from the document and write it to another word document.
    Is it possible to do this?
    Can anyone give me some idea?
    Any idea is much appreciated :)

    I think I may have misunderstood your question, but in case I didn't and you find this helpful, following is the code to read a word doc, replace certain strings, then write it out as a new doc.
    import java.io.*;
    public class Copy {
         public static String endResult;
         public static void main(String[] args) {
              String oldAuthor = "Samuel Foote";
              String newAuthor = "New Author";
              String oldDate = "1720-1777";
              String newDate = "1975 -- ";
          try {
              File inputFile = new File("C:\\document.doc");
              BufferedReader input = null;
              input = new BufferedReader(new FileReader(inputFile));
              StringBuffer contents = new StringBuffer();
              String line = null;
              while ((line = input.readLine()) != null){
                   contents.append(line);
                   contents.append(System.getProperty("line.separator"));          
              String text = contents.toString();
    //     Replace the author and the dates
              Copy y = new Copy();
              y.replace(text, oldAuthor, newAuthor);
              text = endResult;
              y.replace(text, oldDate, newDate);
    //     Copy the new, improved text to another file     //
              Copy z = new Copy();
              z.finalReplace(text);
              input.close();
         catch (FileNotFoundException ex) {
              ex.printStackTrace();
         catch (IOException ex){
              ex.printStackTrace();
         String replace(String text, String oldSubstring, String newSubstring) {
    //          Search the text for a string, then replace it //
              int fromIndex = 0;
              int e = 0;
              StringBuffer sb = new StringBuffer();
              while ((e = text.indexOf(oldSubstring, fromIndex)) >= 0) {
                   sb.append(text.substring(fromIndex, e));
                   sb.append(newSubstring);
                   fromIndex = e + oldSubstring.length();
              sb.append(text.substring(fromIndex));
              endResult = sb.toString();
              System.out.println("final string = " + sb);
              return sb.toString();
         String finalReplace (String args) throws IOException {
    //          Move the altered text to a new file  //
              File outputFile = new File("C:\\copied document.doc");
              FileWriter out = new FileWriter(outputFile);
              Writer output = null;
              try {
                   output = new BufferedWriter(new FileWriter(outputFile));
                   output.write(endResult);
              finally {
                   if (output != null) output.close();
                 return endResult;

  • Procedure to write in file using spool otoption

    Hi
    Please find the below procedure to spool a file from procedure using execute immediate..
    create or replace procedure file_write
    IS
    sethead varchar2(1500);
    setserve varchar2(1500);
    setspool varchar2(1500);
    setspoolof varchar2(1500);
    Begin
    sethead:='set feedback off verify off heading off pagesize 0';
    setserve:='set serveroutput on';
    setspool:='spool C:\file_check_spool.txt APPEND';
    setspoolof:='spool off';
    execute immediate(sethead);
    execute immediate (setserve);
    execute immediate (setspool);
    dbms_output.put_line('no errors');
    execute immediate (setspoolof);
    EXCEPTION
    THEN
    execute immediate(sethead);
    execute immediate (setserve);
    execute immediate (setspool);
    dbms_output.put_line('-20001,Error Encountered - file_check - '||SQLCODE|| '-'|| SQLERRM);
    execute immediate (setspoolof);
    end file_write;
    Please suggest ...
    i cant able to use file utilities ...only by this way or any other option is there
    Thanks in advance

    You would need to create a sql script to run the procedure, something along the lines of:
    set feedback off verify off heading off pagesize 0 serveroutput on;
    spool C:\file_check_spool.txt APPEND;
    exec your_procedure;
    spool off;Then your procedure would look something like:
    create or replace procedure my_proc
       <declarations>
    begin
       <do stuff>
       dbms_output.put_line('no errors');
    exception
       when <trap exception here> then
          dbms_output.put_line('Error Encountered - file_check - 'SQLERRM);
    end;Note that there is no need to outpu both SQLCODE and SQLERRM since SQLERRM contains the value of SQLCODE.
    Note also that depending on your version of Oracle, there are limits on how much data can be put into the dbms_output buffer.
    John

Maybe you are looking for

  • MacBook Pro 1,1 will not wake up under Windows XP

    I have an "old" macbook pro 1,1 (one of the first Intels) with ATI Radeon X1600 128MB and I am having trouble with it waking from sleep under Windows XP bootcamp. This is a similar problem as in this thread: http://discussions.apple.com/thread.jspa?t

  • Bank Reconciliation Report  SAP B1 2005 or 2007 versions

    Any progress made here ? Needs to have cashbook balance, list of unreconciled transactions and a bank statement balance. Can provide an example if needed. Interesting the Banking section has been revamped in 2007 version without such a standard repor

  • Signature Acting up in 9 Pro, working fine in Reader

    I am having problem signing the forms in Adobe9 Pro. Getting an error (image attached). This is not an issue on Adobe9 Reader. Help!

  • How can i run my java Application stand alone?

    Dear all, As the topic i want to run my application in a single file without showing the dos prompt or type in the command in dos prompt by the user...... How can i do that, since in my application , i have used so other package? In fact i just want

  • Losting the photos in iCloud..Can I get them back ??

    I got the new iPhone and back up all the photos to iCloud from my old iPhone. However, I dont know that there is 30 days rules. So, I didnt save all of my iClouds photo to my new phone. And few days ago, I found that all of my photos were gone from t