BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 10-10-2007, 09:25 PM   #1 (permalink)
Thumbs Must Hurt
 
Join Date: Jun 2007
Model: 8800
PIN: N/A
Carrier: GPRS
Posts: 68
Post Thanks: 0
Thanked 0 Times in 0 Posts
Red face Can we write our own log file in BB

Please Login to Remove!

Hi, all:

I want to write a log file for my app , and I find that the old messages always covered by the new ones. There is only one message in my log file. As well known , we can set the mode of fileconnection, but there are only three ways in BB: WRITE, READ, READ_WRITE. So we couldn't set the APPEND mode? Is there any other ways?
Thank you very much!

My code here is :
Code:
FileConnection fconn = (FileConnection)Connector.open("file:///SDCard/BlackBerry/pictures/1.txt",Connector.READ_WRITE); 
                        if (!fconn.exists()) 
                        { 
                            fconn.create(); 
                            System.out.println("Create a new file!"); 
                            OutputStream out = fconn.openOutputStream();                             
                            out.write(buffer1.toString().getBytes()); 
                            out.close(); 
                        } 
                        else
                        {
                            OutputStream out = fconn.openOutputStream();                             
                            out.write(buffer1.toString().getBytes()); 
                            out.close(); 
                            }
Offline  
Old 10-11-2007, 02:17 AM   #2 (permalink)
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

you can take a look at net.rim.device.api.system.EventLogger if you have problems with your own logger.

gs
simon
__________________
java developer, Devinto, hamburg/germany
Offline  
Old 05-22-2008, 12:45 PM   #3 (permalink)
Thumbs Must Hurt
 
Join Date: May 2008
Model: 8700
PIN: N/A
Carrier: Telcel
Posts: 69
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

It may sound silly, and I may be reviving a pretty old topic, but, try adding a "\n" (a jump line character) at the end of each line. Because the cursor is stuck on the same line it always write on that line... or something like that, I think
Offline  
Old 05-28-2008, 01:42 AM   #4 (permalink)
New Member
 
Join Date: May 2008
Model: 8830
PIN: N/A
Carrier: Sprint
Posts: 7
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by CJLopez View Post
It may sound silly, and I may be reviving a pretty old topic, but, try adding a "\n" (a jump line character) at the end of each line. Because the cursor is stuck on the same line it always write on that line... or something like that, I think
New lines aren't the issue here. The issue is that if the file exists and has data in it write, print, and println all start at the beginning of the file. The issue then becomes how, within the FileConnection/OutputDataStream world, can you get to the end of the file? Sure, we could just read the contents of the file into a variable, append to that variable, and then write back to the file, but that's a bit ridiculous.

There has to be some kind of seek() or skip() function that we can use to move the stream pointer to the end of the file. Does anybody know how to do this?
Offline  
Old 05-28-2008, 01:58 AM   #5 (permalink)
Talking BlackBerry Encyclopedia
 
richard.puckett's Avatar
 
Join Date: Oct 2007
Location: Seattle, WA
Model: 9020
PIN: N/A
Carrier: T-Mobile
Posts: 212
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

How about FileConnection.openOutputStream(long byteOffset)?
__________________
Do your homework and know how to ask a good question.
Offline  
Old 05-28-2008, 11:06 AM   #6 (permalink)
New Member
 
Join Date: May 2008
Model: 8830
PIN: N/A
Carrier: Sprint
Posts: 7
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

For crying out load! It always amazes me how stupid a few hours of sleep and somebody pointing out how stupid I've been can make me feel.

Thanks. Yes, folks, the key is not to fixate on openDataOutputStream.

Code:
        PrintStream logStream;
        try
        {
            String _logURL = "file:///SDCard/log.txt";
            FileConnection fconn = (FileConnection)Connector.open(_logURL);
            // If no exception is thrown, then the URI is valid, but the file may or may not exist.
            if (!fconn.exists())
            {
                fconn.create();
            }
            logStream = new PrintStream(fconn.openOutputStream(fconn.fileSize()));
        }catch (IOException ioe) {
            System.out.println("File error: " + ioe.toString());
        }catch (Exception e){
            System.out.println("General File error: " + e.toString());
        }
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.