Unable to establish the connection to the file in BlackBerry

Posted by Vikas on Stack Overflow See other posts from Stack Overflow or by Vikas
Published on 2011-12-01T09:15:38Z Indexed on 2011/12/01 9:50 UTC
Read the original article Hit count: 148

Filed under:
|
|
|

I have tried the example code on SO to read the contents from the file in the resource directory in BlackBerry. But I am having an issue with the FileConnection. I get the following error:

File system error (1003)

I tried the example from here. I want only the read functionality, the file I want to read is in CSV format as a .txt file placed in the /res/test.txt.

public class FileDemo extends MainScreen {

public FileDemo() {

    setTitle("My Page");
    String str = readTextFile("file:///test.txt");
    System.out.println("Contents of the file::::::: " + str);
}

public String readTextFile(String fName) {
    String result = null;
    FileConnection fconn = null;
    DataInputStream is = null;
    try {
        fconn = (FileConnection) Connector.openInputStream(fName);
        is = fconn.openDataInputStream();
        byte[] data = IOUtilities.streamToBytes(is);
        result = new String(data);

    } catch (IOException e) {
        System.out.println(e.getMessage());
    } finally {
        try {
            if (null != is)

                is.close();
            if (null != fconn)
                fconn.close();
        } catch (IOException e) {
            System.out.println(e.getMessage());
        }
    }
    return result;
}

}

Any suggestions/advice on a better approach or as to how I can get this working??

© Stack Overflow or respective owner

Related posts about java

Related posts about file