BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 03-17-2009, 11:55 AM   #1 (permalink)
New Member
 
Join Date: Mar 2009
Model: 8310
PIN: N/A
Carrier: Telkomsel
Posts: 7
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Is FileConnection enough for manipulating file?

Please Login to Remove!

Dear all,

I have read a several articles about file operation is BB Java Development that reading a file must be started from the root directory :

Code:
Connector.open("file:///store/home/user...");
Let's say that a method tries to read a file from the "resource" directory of a project, means that it doesn't know the full path from /store/home/... to the resource directory.

Probably like this :

Code:
Connector.open("file:///resource/icon.jpg");
Is that possible? If not, why? Is there any another way to do that?
Offline  
Old 03-17-2009, 03:27 PM   #2 (permalink)
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
Post Thanks: 20
Thanked 77 Times in 68 Posts
Default

You can't read project resources with a file connector like that. Use:
Code:
InputStream inputStream = getClass().getResourceAsStream( "/resource/icon.jpg" );
Or if what you want it the icon:
Code:
icon = Bitmap.getBitmapResource("/resource/icon.jpg");
Offline  
Old 03-17-2009, 10:00 PM   #3 (permalink)
New Member
 
Join Date: Mar 2009
Model: 8310
PIN: N/A
Carrier: Telkomsel
Posts: 7
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi, thanks for your reply.

Actually i want to open an OutputStream for that file, means that i want to write some contents.

As long as i concern, and correct me if i'm wrong, the only way to open an OutputStream is through a FileConnection.

Code:
OutputStream os = ((FileConnection)Connector.open("file:///store/home/user/a.txt")).openOutputStream();
Do i miss something about IO API in JDE?
Offline  
Old 03-18-2009, 05:08 AM   #4 (permalink)
Talking BlackBerry Encyclopedia
 
Join Date: Apr 2008
Location: Germany, BW
Model: -
PIN: N/A
Carrier: -
Posts: 310
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

the only way to manipulate a precompiled file is to read it in a byte array and write it to the file system as file. You can then either manipulate it as long as it is in the array or when it is in the file system. You cannot write it back in your application cod.
__________________
Blessed is the end user who expects nothing, for he/she will not be disappointed. (Franklin's Rule)
Offline  
Old 03-23-2009, 01:13 AM   #5 (permalink)
Knows Where the Search Button Is
 
Join Date: Feb 2009
Model: 9000
PIN: N/A
Carrier: AT&T
Posts: 16
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Dare I ask why are you trying to modify a resource that shipped in the .cod?
If your man enough to have a crack at modifying the byte code then more power to ya!
One sensible use case for this might be to scale images for a specific device. In such a case you can either:
1. Create separate app bundles for each and every device (quite tedious) or:
2. Scale the images etc and store copies of them on the filesystem.

Your app would need to check upon startup for the existence of these scaled images on the filesystem before it goes scaling at runtime, this would mean that you only take a one time startup performance hit to perform the image scaling.
Offline  
Old 05-26-2009, 06:29 AM   #6 (permalink)
New Member
 
Join Date: May 2009
Model: 7290
PIN: N/A
Carrier: meet bug in blackberry JDE 4.7.0
Posts: 3
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Dear All,

When i coding for reading csv & txt file, I have a problem similar with siagianfaber. And i have do follow everyone who have reply in this topic.
At last i have not reading csv & txt file. I'm using the "Blackberry JDE 4.7.0" tool and run it on Windown xp sp2. please help me if you know !

here is my code:

String filePath = "file:///store/home/user/test.txt";
FileConnection fc = (FileConnection)Connector.open(filePath,Connector. READ_WRITE);
if(!fc.exists()) {
throw new IOException("File does not exist");
}
InputStream is = fc.openInputStream();

Thanks & Best regards,
Tiep Le
Offline  
Old 08-26-2009, 05:48 PM   #7 (permalink)
New Member
 
Join Date: Aug 2009
Model: 8300
PIN: N/A
Carrier: none
Posts: 4
Post Thanks: 0
Thanked 0 Times in 0 Posts
Red face

Tiep Le,

From your question it is not clear whether you are trying to find a file that is on the BlackBerry or one that you created in your JDE project. If it is on the BlackBerry file system then this should work ok - you'd want to make sure that the file test.txt is really in the user directory. I haven't done this yet myself but I was able to read a new picture taken by the camera using the line

Code:
String filePath = "file:///SDCard/BlackBerry/pictures/test.jpg";
FileConnection fc = (FileConnection)Connector.open(filePath);
I'm still just using the 9000 simulator and the eclipse plug-in.
The actual photo when I select it and look at the Properties claims it is
at /Media Card/BlackBerry/pictures/test.jpg however.

If you are trying to access a file which you created in you project folder then see the post on BlackBerry's - Java Development - BlackBerry Support Community Forums titled (google blackberry and this title):

"Not able to read text or binary file"
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.