Repository navigation
Modern Fs TextWriter
Paul Squires edited this page Nov 9, 2026
·
5 revisions
Home › Filesystem › File Streams › TextWriter
Holds a writer that sends text to any Stream as UTF-8, with an optional BOM.
type TextWriter
declare constructor( byref inner as Stream, byval writeBom as boolean = FALSE )
declare constructor( byref inner as Stream, byval enc as TextEncoding, byval mode as TextErrorMode = TEXT_STRICT )
as ustring NewLine '' chr( 13, 10 ) on Windows, chr( 10 ) on Linux and macOS
Write( s ) / WriteLine( [ s ] ) / Flush( )
end type- A wrapper does not own what it wraps: it keeps a pointer to the stream it was given, which must outlive it. It cannot be copied.
- UTF-8. With writeBom the byte-order mark is written once, before the first text. A lone surrogate is written as U+FFFD.
- With an encoding: its byte-order mark, if it has one, before the first text. Each Write is encoded in full before any of it is written. Under TEXT_STRICT, the default, a Write holding a character the encoding cannot represent fails with FS_INVALID_DATA and writes nothing. Under TEXT_REPLACE that character becomes ?, and the call returns false instead of true. See Choosing An Encoding.
- NewLine is platform-native by default. Set it to chr( 10 ) for a file that must be identical on every platform. Only WriteLine uses it; Write writes its text exactly as given.
- It buffers nothing itself: wrap a BufferedWriter for many small writes.
#import "std/fs"
using fs
dim as MemoryStream m
dim as TextWriter tw = TextWriter( m )
tw.NewLine = chr( 10 )
tw.WriteLine( "first" )
tw.Write( "second" )
print m.Length( ) '' 12Library: Filesystem Library Category: File Streams Documented under: Streams
tiko-lang · Home · Feature Index · Keyword Index · License
FreeBASIC manual pages reproduced under the GNU FDL 1.3.
- Generics
- Interfaces
- For Each
- Iterators
- Tuples
- Array Results
- Defer
- Lambdas
- Block Strings
- Partial Types
- String Slices
- Embed
- Typed Variadics
- C Header Import
- Foreign Library Linking
- UString
- Fixed-Width Types
- Nullptr
- String Library
- Format
- Array
- Map
- Set
- LinkedList
- OrderedMap
- OrderedSet
- Sorting
- Optional
- Result
- Smart Pointers
- Date and Time (Chrono)
- Filesystem
- File Streams
- Config (INI and TOML)
- Codec
- Hash
- UUID
- OS
- Process
- Net
- HTTP and TLS
- Math Library
- Finance
- Logging
- Terminal TUI Library
- PsControls
- tkControls
- sys/win
- Goroutines and Channels
- LLVM Backend
- tiko build
- TIKO_COMPILER
- Variable Declarations
- Standard Data Types
- User Defined Types
- Procedures
- Operators
- Control Flow Statements
- Converting Data Types
- Array Functions
- String Functions
- Mathematical Functions
- Bit Manipulation
- Date and Time Functions
- File I/O Functions
- Console Functions
- User Input (Runtime Library)
- User Input Functions (Graphics Library)
- Screen Functions
- 2D Drawing Functions
- Graphics Library Reference
- Graphics Keyword List
- Memory Functions
- Threading Support Functions
- Error Handling Functions
- Operating System Functions
- Preprocessor
- Intrinsic Defines
- Miscellaneous Keywords
- Modularizing