Files and Structured I/O
-
Absolute and Relative File Paths
An absolute path identifies a location from a filesystem root. A relative path needs a base directory supplied by the process or caller.
-
Combining Path Components
A path library can join a base folder and relative components under the rules of the target operating system.
-
Opening a Text File with an Explicit Encoding
Opening a file as text asks the runtime to decode bytes. Choosing the encoding explicitly makes the result independent of many environment defaults.
-
Opening a File in Binary Mode
A binary stream reads bytes and writes bytes. This preserves exact line endings and encoded data for a format parser or archive.
-
File Modes for Reading, Writing, and Appending
A file open mode determines which operations are permitted and whether an existing file is preserved, truncated, or extended.
-
Closing Files with a Context Manager
A context manager gives acquired file resources a scope. Exiting that scope closes the file whether ordinary processing finishes or an exception propagates.
-
Reading a File Line by Line or All at Once
A line-based reader can process records as they arrive. Reading the entire file is useful when evaluation needs a bounded whole document.
-
Reading Fixed-Size Blocks from a Stream
A bounded read requests at most some number of bytes. Depending on the interface, a short result can require handling instead of assuming a full record.
-
File Positions and Seeking
A seekable stream can move its position before the next read or write. Offset rules depend on the stream type.
-
Detecting End of File Without Losing a Record
An input API signals when no more data is available. Detect that signal separately from ordinary empty fields and short final records.
-
Buffered Writes and Flushing
A writer can hold bytes in a buffer before delivering them to the next layer. A flush asks that layer to receive the buffered output.
-
Replacing a Generated File After a Complete Write
A generated output can be written to a temporary file and then moved into place with an atomic replacement operation on a supported filesystem.
-
Temporary Files and Their Lifetime
A temporary file can hold intermediate data without committing a result to its long-term path. Define who owns it and when it is cleaned up.
-
Processing Directory Entries in a Stable Order
Filesystem enumeration need not return a useful sort order. Select a sort key when a result depends on the visitation sequence.
-
File Metadata and File Content
Metadata can describe an entry's name, permissions, size, or timestamps. Several of those values can change without an edit to the logical document.
-
Reading Text from Standard Input
A command can consume standard input supplied by a terminal, redirected file, or upstream program without choosing the path itself.
-
Standard Output and Standard Error
A process can emit ordinary output and diagnostics through separate streams, letting a caller capture or redirect them independently.
-
Giving a File Import a Size Budget
An importer can declare limits on bytes, records, and parsed expansion so it uses resources predictably on valid and invalid inputs.
-
Parsing Text into Records in Stages
A staged reader can separate decoding, record boundaries, field conversion, and domain validation so each failure has a location.
-
Converting Records Without Loading the Entire File
A stream-to-stream conversion can read one record, transform it, and write the output before reading the next.
-
Distinguishing File Open, Read, and Decode Errors
Opening a path, reading data, and interpreting what was read can fail for different reasons.
-
Separating Read-Only Inputs from Writable Results
Using an input stream for reading and a different output stream for writing makes file ownership and observed effects easier to review.
-
Verifying a Written File at the Consumer Boundary
Testing a file writer works best by reading its actual output under the expected consumer contract.
-
Returning Typed Records and Diagnostics from a Reader
A reader can expose parsed values together with source locations or reasons for rejected records, according to its error policy.
-
Checking Metadata Before Reading Large Input
File metadata can guide whether a reader attempts an operation, but actual bytes and filesystem state can change before or during the read.
-
Reading a Small Configuration File
Configuration should have a declared structure, visible defaults, and a clear reaction to invalid supplied values.
-
When a Cached File Result Becomes Stale
Caching a parsed result by path alone can return old data when the same path begins naming updated content.
-
Files, Directories, and Other Directory Entries
A directory can contain ordinary files, other directories, links, and other entry types supported by the platform.
-
Writing a Final Newline Deliberately
A record writer needs to decide whether every record ends with a newline or whether newlines only separate adjacent records.
-
Making a Repeatable File Export
A repeatable export from unchanged inputs gives the same logical contents or bytes, depending on its declared guarantee.