Symbian File Operations

Source: Internet
Author: User
Symbian provides file servers (rfile) and file sessions (RFS) to support file operations. Like a PC, Symbian also supports long file names, but does not support "." and "..". Symbian provides a tfilename class to represent the file name. Its definition is: typedef tbuf <kmaxfilename> tfilename kmaxfilename = 256. Because it is too resource-consuming, we recommend that you do not use it whenever possible.

The file server provides directory and file management functions. The related libraries and header files are efserv. lib and f32file. h. First, let's talk about the directory. The cdir and tentry classes are used to represent the directory. Cdir is used to store the file sequence in the current directory, similar to an array. Tentry indicates every element in cdir. You can obtain the tentry object through [] of cdir overload. Before using the file server, you must establish a file session through RFS connect. Getdir (const tdesc & aname, tunit aentryattmask, tunit aentrysortkey, cdir * aentrylist) const obtains the file sequence of the current directory. According to the parameter name, we can deduce what they represent.
File management. You can use the File Server to read, write, delete, and create files. Before doing this, open the file. It is implemented through rfile open (rfs afs, const tdesc & aname, tunit afilemode. Write () and read () can be used to write and read files. Both functions have two versions: synchronous and asynchronous. Rfile's create () is used to create a new file. You can use RFS Delete () to delete the file (). For more information, see SDK help. Close () after using rfile and RFS.

There are two important things in file management: stream and storage.
The concept of stream is not introduced. I believe everyone is familiar with it. Symbian encapsulates two streams: rwritestream is the base class of the output stream, and rreadstream is the base class of the input stream. On this basis, the output/input streams are derived: rfilewritestream and rfilereadstream. After instantiating the file output stream, call Replace () to create the output stream (assuming the file to be written does not exist), and then pushl () to push the output stream to the clear stack. After that, you can write data to the stream. Call commitl () to submit the data of the output stream. Call POP () and release () of rfilewritestream. The two statements are also equivalent to cleanupstack: popanddestory (). The specific role will not be mentioned. This is the process of writing data through a flow object. The process of reading data from a file through a stream is similar to that of writing data. When writing data to hbufc, you can use newl (astream, kmaxtint) of hbufc to create a heap descriptor.
The Symbian conventions require that an accessible public externalozel () function be provided for any object that can be turned externally as a stream. This function uses the reference of an output stream as a parameter to encapsulate the process of writing data to the stream. Likewise, an internalizel () can be provided to read data.

Storage is a collection of multiple streams. Two file-based storage types are cdirectfilestore and cpermanentfilestore. The latter can be modified after writing, but the former cannot. Here we have a unique Symbian concept: stream dictionary ). It is just another stream, but it stores the ing between other stream IDs and the corresponding stream uid. You can find the desired stream from the stream dictionary just like you can look up the dictionary.
The general method of using storage is as follows:
Void createdirectfilestorel (RFS & AFS, tdesc & afilename, tuid aappuid)
{
Cfilestore * store = cdirectfilestore: replacelc (AFS, afilename, efilewrite); // create a store
Store-> settypel (tuidtype (kdirectfilestorelayoutuid, kuidappdlldoc, aappuid); // set the type
Cstreamdictionary * dictionary = cstreamdictionary: newlc (); // create a stream dictionary

Rstorewritestream stream; // write stream
Tstreamid id = stream. createlc (* store); // get the stream ID
Tint16 I = 0x1234;
Stream <I;
Stream. commitl ();
Cleanupstack: popanddestory (); // write

Dictionary-> assignl (aappuid, ID); // associate the stream ID in the stream dictionary

Rstorewritestream rootstream;
Tstreamid rootid = rootstream. createlc (* store );
Rootstream <* dictionary;
Rootstream. commitl ();
Cleanupstack: popanddestory (); // root stream

Store-> setroot (rootid); // you can specify the root stream ID.
Store-> commitl ();

Cleanupstack: popanddestory (); // Storage
}

The method for reading data from storage is to reverse the above process:
Void readdirectfilestorel (RFS & AFS, tdesc & afilename, tuid aappuid)
{
Cfilestore * store = cdirectfilestore: openlc (AFS, afilename, efileread); // create a storage

Cstreamdictionary * dictionary = cstreamdictionary: newlc (); // create a stream dictionary

Rstorereadstream rootstream; // root stream
Rootstream. openlc (* store, store-> root (); // open the root stream
Rootstream> * dictionary; // write stream dictionary
Cleanupstack: popanddestory ();

Tstreamid id = dictionary-> at (aappuid); // create a ing

Cleanupstack: popanddestory ();

Rstorereadstream stream;
Stream. openlc (* store, ID );
Tint16 J;
Stream> J; // read data

Cleanupstack: popanddestory ();
Cleanupstack: popanddestory ();
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.