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

Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.

Posts: 49
Registered: ‎05-02-2012
My Device: Bold 9790
My Carrier: Wind Mobile
Accepted Solution

Copy file in 'res' to file system

[ Edited ]

Hi there,


I'm trying to copy a file from my .cod file into the file system so I can overwrite it etc. However, I can't seem to get the file to write. This is the code I'm using right now, I found it when searching the community.


try {
            FileConnection fc = (FileConnection) Connector.open("file:///store/home/holidays.xml");
            if (!fc.exists()) {
                OutputStream os = fc.openOutputStream();
                InputStream is = getClass().getResourceAsStream("/xml/holidays.xml");
                byte[] buf = new byte[1024];
                int len = 0;
                while ((len = is.read(buf)) > 0) {
                    os.write(buf, 0, len);
                add(new LabelField("Wrote file."));
        } catch (IOException e) {


This is in the constructor for the screen. When I run the app, I dont get "Wrote file.", just a blank screen. Any suggestions on what I'm doing wrong?


Thank you in advance,


Posts: 729
Registered: ‎05-04-2011
My Device: 9700

Re: Copy file in 'res' to file system

Hi Ben,


Use a debugger to see which line is throwing an error.


Once you will have that, it will be easier to find a solution.


Also, are you sure that:


1. The file file:///store/home/holidays.xml doesn't already exist?


2. The path/xml/holidays.xml is the correct path for the resource file?


Hope that helps,



Posts: 49
Registered: ‎05-02-2012
My Device: Bold 9790
My Carrier: Wind Mobile

Re: Copy file in 'res' to file system

Thanks for the advice,


I finally figured out what was going on; something about reading the xml/holidays.xml file wasn't working at all. In the end I read from a holidays.txt file to an xml file in the file system. Its not a good solution but it works fine now.




Regular Contributor
Posts: 81
Registered: ‎01-16-2012
My Device: BOLD 9650 + developer
My Carrier: Vodafone

Re: Copy file in 'res' to file system

try to put the name  like that