BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 08-30-2010, 08:43 AM   #1 (permalink)
New Member
 
Join Date: Aug 2010
Model: 9550
PIN: N/A
Carrier: 1
Posts: 5
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Reading data from a text file

Please Login to Remove!

Hi!!

Can someone provide sample code to read data from a file present in SDCard.

Thanks,
Pavan Kumar
Offline  
Old 09-15-2010, 10:29 AM   #2 (permalink)
New Member
 
RockoAndy's Avatar
 
Join Date: Sep 2010
Model: 8900
PIN: N/A
Carrier: Airtel
Posts: 11
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hey pavan try this..


Code:
try {
			FileConnection con = (FileConnection) javax.microedition.io.Connector.open("file:///SDCarc/blackberry/");
			if(con.exists())
			{
				InputStream input = con.openInputStream();
				StringBuffer buffer = new StringBuffer();
				while(input.read() != -1)
				{
					buffer.append(input.read());
				}
				System.out.println("OutPut"+buffer.toString());
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
by the way where r u frm?
__________________
the amazing world of
Offline  
Old 09-29-2010, 02:39 AM   #3 (permalink)
New Member
 
Join Date: Sep 2010
Model: 9650
PIN: N/A
Carrier: verizon
Posts: 5
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm trying to do something similar, and I have code that is almost identical (by the way, you have a typo - SDCarc -> SDCard).

I am getting an error on the (FileConnection)Connector.open() line - but I can't find the stacktrace on the simulator to see what it is. Every other attempt to track this error has failed. Do you know how to find the stacktrace on the simulator?

Also, do you know what the likely cause of errors here are? I assume it's not "file not found", otherwise your coding would make no sense (you have if(con.exists()) right after that line).

Jared
Offline  
Old 10-09-2010, 02:30 AM   #4 (permalink)
New Member
 
Join Date: Sep 2010
Model: 9650
PIN: N/A
Carrier: verizon
Posts: 5
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

OK, I think I am getting it to work, now I just need to wrestle with getting my file in the right place. Is there anyway to access my application's directory? I can open an HTML file located at "local:///res/test.html", but can I open a text file in this location? I keep getting File System errors when I try.

Jared
Offline  
Old 10-09-2010, 10:09 AM   #5 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts
Default

You cannot "open" a file that is in your distribution COD. For this you need to utilize Class.getResourceAsStream(String resourceName)
Offline  
Old 10-09-2010, 06:13 PM   #6 (permalink)
New Member
 
Join Date: Sep 2010
Model: 9650
PIN: N/A
Carrier: verizon
Posts: 5
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks Doug, that is exactly what I was looking for.

Jared
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.