Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Mar 2010

    Unhappy question about JSR75

    today i wrote programs with jsr75 api as follows:
    FileConnection fc = null;
    OutputStream os = null;
    long size = 0;
    fc = (FileConnection)Connector.open( dir2+fileName, Connector.READ_WRITE);
    if( !fc.exists() ){
    if( isReWrite ){
    size = fc.fileSize();
    fc.truncate(size); }
    os = fc.openOutputStream();
    os = null;
    fc = null;
    result = true;
    }catch(Exception e){
    result = false;
    // dos.close();
    if( os!=null ){
    os = null;
    if( fc!=null ){
    fc = null;
    }catch(Exception e){
    result = false;
    but the result was wrong. According to the codes, every time when I run this app ,the file has always been overwriten.I just want to append sth to the current contents.It failed.I looked up in JSR75 api,and I found that fc.truncate() can do this.So I added it to my code,but it still didn't work. what can I do to solve this problem! can anybody help me?
    thanks in advance!

  2. #2
    Nokia Developer Champion
    Join Date
    Feb 2009
    Noida, India

    Re: question about JSR75

    I see the problem with OutputStream, you need to place it at then end of the file before writing to append to the file, from FCA API doc...:


    public java.io.OutputStream openOutputStream()

    throws java.io.IOExceptionOpen and return an output stream for a connection. The output stream is positioned at the start of the file. Writing data to the output stream overwrites the contents of the files (i.e. does not insert data). Writing data to output streams beyond the current end of file automatically extends the file size. The connection's target must already exist and be accessible for the output stream to be created. openOutputStream(long) should be used to position an output stream to a different position in the file.
    Changes made to a file through an output stream may not be immediately made to the actual file residing on the file system because platform and implementation specific use of caching and buffering of the data. Stream contents and file length extensions are not necessarily visible outside of the application immediately unless flush() is called on the stream. The returned output stream is automatically and synchronously flushed when it is closed.


Similar Threads

  1. Replies: 5
    Last Post: 2010-03-11, 13:04
  2. CCalSession -> question
    By rsiudak in forum Symbian C++
    Replies: 0
    Last Post: 2009-11-04, 16:02
  3. CBase question
    By eric_cartman in forum Symbian C++
    Replies: 9
    Last Post: 2009-09-09, 19:06
  4. Replies: 0
    Last Post: 2009-08-28, 09:39
  5. Replies: 0
    Last Post: 2003-04-07, 09:52

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts