how to load/save a TEXT file (.txt) (ANSI)
RE:how to load/save a TEXT file (.txt) (ANSI)
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.
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.