Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Regular Contributor
Posts: 67
Registered: ‎06-30-2010
My Device: Storm 9550
My Carrier: Airtel
Accepted Solution

saving rss feed as xml file in the device memory

Hi,

 

I am parsing an RSS feed using SAX parser. Now i want to save the RSS feed an an xml file in either the device memory or on SD card. Can anyone guide me through this process

Developer
Posts: 70
Registered: ‎01-02-2009
My Device: Not Specified

Re: saving rss feed as xml file in the device memory

 

To write the rss content to a xml file, first create the file with ".xml" extension using FileConnection API, then write the content(rss data) to the XML file.

 

You can use below code to write the content to the file. You have to give the path as a String & the content in byte format.

 

 

public boolean writeFile(String path, byte[] data) 
    {
        javax.microedition.io.Connection c = null;
        java.io.OutputStream os = null;
        try {
            c = javax.microedition.io.Connector.open("file:///" + path, javax.microedition.io.Connector.READ_WRITE);
            javax.microedition.io.file.FileConnection fc = 
                    (javax.microedition.io.file.FileConnection) c;
            if (!fc.exists())
                fc.create();
            else
                fc.truncate(0);
            os = fc.openOutputStream();
            os.write(data);
            os.flush();
            return true;
        } catch (Exception e) {
            return false;
        } finally {
            try {
                if (os != null)
                    os.close();
                if (c != null)
                    c.close();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }

 

---------------------
Best Regards,
Kannabiran.
---------------------
Don't forget to mark your post as solved if you got answer. And give kudos.