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

Web and WebWorks Development

Posts: 151
Registered: ‎02-19-2011
My Device: Bold 9930 and PlayBook

Problems reading large files with JavaScript

This weekend I've been trying to get my WebWorks (HTML/JavaScript) application to read in a large XML or CSV file.  By large I mean in CSV format it is over 8,500 lines long, about 357KB in size. I have tried a few different ways to read it in:



function getDataFile(filepath) {
	alert("Trying to read: " + filepath)
	request = new XMLHttpRequest();
	try {
		request.open('GET', filepath, true);
		request.onreadystatechange = handleFileResponse; 
	} catch (e) {
		alert("Failed to read data.\n" + e);

function handleFileResponse() {
	if (request.readyState == 4) {
		if (request.status == 200 || request.status == 0) {

I make the call to the function as such: getDataFile('local:////data.xml');

I tried using just three forward slashes, local:///, but that never seemed to work for me so I stuck with using four.  Anyways, I've successfully run this function and received the text in the file with the file was small, maybe a few dozen lines.  But if I use a file around one or two thousand lines it appears that handleFileRequest never gets called with the file text.


Doing some research I found blackberry.io library that could be used:


function openFile(fileName) {
    // if the file exists
	alert("Trying to get: " + fileName);
	if (blackberry.io.file.exists(fileName)) {
		// read it
		alert("Found the file");
		blackberry.io.file.readFile(fileName, doCallback);
	// file not found
	else {
		alert('file not found: ' + fileName);

This never gets past the if statement which I think I found in another forum is a bug in the library.


So what I'm trying to find out is how can I read a large CSV or XML file in JavaScript with WebWorks?  I'm not tied to it being in CSV format, honestly if I can get the file read in then I'll probably try to put all the data into the database so I don't have to read it every time.  If it matters at all I'm testing on the PlayBook simulator 0.9.3.




"Not to know what happened before you were born is to be forever a child." Marcus Tullius Cicero
Posts: 57
Registered: ‎01-29-2009
My Device: Not Specified

Re: Problems reading large files with JavaScript

I really love to know this using web works.

Let me know if you find the way to do this.