how to load/save a TEXT file (.txt) (ANSI)

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
sg

how to load/save a TEXT file (.txt) (ANSI)

Post by sg »

thanks
Schol-R-LEA

RE:how to load/save a TEXT file (.txt) (ANSI)

Post by Schol-R-LEA »

To save text data to a disk, all you need to do is save it exactly as it is, in 512 byte chunks, to one or more sectors, making sure that you know which sectors hold the data in question. Writing would work the same way.

Of course, to save a *file* of any kind, you have to implement the file system, which takes care of all those details for you. How you would save text files would depend on what FS you are using.

In most current file systems, there's no specific difference between a text file from any other type of data; files are abstracted as a kind of stream that has been 'frozen' on the disk, a "bag o' bytes" as someone once put it. In suh systems, file types are solely indicated by file name extensions, although many file formats (but not plain ASCII text) have some sort of 'magic cookie' in their header to indicate that it is in fact the correct file type to the programs which use them. Unless the file system requires some kind of meta-file data (i.e., resource forks in the Macintosh's HFS), you can probably just save it byte-for-byte as it is in memory.

Let us know if you need any help on implementing a file system.
Post Reply