×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Regular Contributor
    Join Date
    Jul 2005
    Posts
    95

    Read from a text file

    Hi !

    In my program I use the following code to write to a text file :

    Code:
    void CMyAppContainer::OnJPEGViewCommand(TInt aCommand)
    {
    
     RFs fs;
     fs.Connect();
    
     RFile myfile;
     myfile.Replace(fs,_L("c:\\system\\apps\\format.txt"),EFileWrite); 
         
    
     TBuf8<10> data; //data contains the required format
    
     data.Copy(_L("JPEG"));
    
     myfile.Write(data);
    
     myfile.Close();
     fs.Close();
    
    }
    The above code gets executed when the JPEG menu option is selected. In addition to JPEG ,i also have similar code for other image formats like GIF,PNG,TIFF etc..
    So basically what happens is when the user selects a particular format from a menu that format gets written to a text file.
    Now what I would like to do is read that text from the text file and take appropriate actions based on the format read.
    The following pseudocode may help in clarifying what I need to do :


    switch(<format>)
    {
    case "JPEG " :

    //do something for JPEG

    break ;

    case "GIF"

    //do something for GIF

    break ;

    ....
    ....

    default :

    break ;

    }

    Being a symbian newbie I am facing difficulty in reading from the file. So, id appreciate it if u could show me how reading from the format.txt file and using the format in a switch block could be implemented.

    Thanks a lot

  2. #2
    Super Contributor
    Join Date
    May 2005
    Location
    Hyderabad,India
    Posts
    704

    Re: Read from a text file

    hi,

    I think you need to read from the jpeg file and write it into a text file.

    //Code

    RFs iSession;
    RFile iFileIn,iFileOut;
    iSession.Connect();
    iFileOut.Open(fs,_L("c:\\system\\apps\\format.txt"),EFileRead);
    TInt size;
    iFileOut.Size(size);

    HBufC8 *iBuf=HBufC8::NewL(size);

    iFileOut.Read(fs,iBuf->Des())

    Now JPEG comes into iBuf.

  3. #3
    Regular Contributor
    Join Date
    Jul 2005
    Posts
    95

    Re: Read from a text file

    Hi ! Eswar ,

    Thanks a lot for replying .After I posted the problem I tried a few things and actually got it to work by using a different approach that involves using a TBuf instead of HBufC that you have used.
    My code is as follows :

    Code:
    RFs sessionhandle ;
    
    RFile file ;
    
    User::LeaveIfError(sessionHandle.Connect());
    
    _LIT(KFile,"c:\\system\\apps\\format.txt");
    
    TBuf8 <30> buf ; //**********Using a TBuf8**********
    
    User::LeaveIfError(file.Open(sessionHandle,KFile,EFileRead));
    
    //Read the text into a buffer
    
    User::LeaveIfError(file.Read(buf)); //buf now contains the text from the file
    
    file.Close();
    sessionHandle.Close();
    I then use the Compare() function to compare the string read with a predefined value .

    Again, thanks for showing me another way to make it work

  4. #4
    Registered User
    Join Date
    Jun 2008
    Posts
    2

    Re: Read from a text file

    Hi razas,

    I m new to Symbian Devlopment,

    after placeing the code i m getting error:

    "undefined identifier 'sessionHandle'"

    Please help me regarding this.


    Regards,
    Rama Krishna

  5. #5
    Nokia Developer Champion
    Join Date
    Jun 2008
    Location
    Noida,India
    Posts
    4,020

    Re: Read from a text file

    you need to include f32file.h in your cpp file

Similar Threads

  1. Help me read a text file
    By margaretpoor in forum Symbian
    Replies: 1
    Last Post: 2004-05-24, 04:08
  2. read file and display contents
    By sajindra in forum Symbian
    Replies: 0
    Last Post: 2004-05-16, 18:55
  3. File Handling... Read files from /res
    By Ralpharama in forum Mobile Java General
    Replies: 2
    Last Post: 2003-10-02, 17:30
  4. Format text read from a file in Edwin Control
    By Vani in forum Symbian User Interface
    Replies: 1
    Last Post: 2003-07-02, 06:36
  5. C++, adding line break to text file
    By rampe29 in forum Symbian
    Replies: 2
    Last Post: 2002-06-18, 06:20

Posting Permissions

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