# Poco

# class FileStream

Library: Foundation
Package: Streams
Header: Poco/FileStream.h

## Description

A stream for reading from and writing to a file.

Files are always opened in binary mode, a text mode with CR-LF translation is not supported. Thus, the file is always opened as if the std::ios::binary flag was specified. Use an InputLineEndingConverter or OutputLineEndingConverter if you require CR-LF translation.

A seek (seekg() or seekp()) operation will always set the read position and the write position simultaneously to the same value.

On Windows platforms, UTF-8 encoded Unicode paths are correctly handled.

## Inheritance

Direct Base Classes: FileIOS, std::iostream

All Base Classes: FileIOS, std::ios, std::iostream

## Member Summary

Member Functions: open

Inherited Functions: close, flushToDisk, nativeHandle, open, openHandle, rdbuf, size

## Constructors

### FileStream

FileStream();

Creats an unopened FileStream.

### FileStream

FileStream(
const std::string & path,
std::ios::openmode mode = std::ios::out | std::ios::in
);

Creates the FileStream for the file given by path, using the given mode.

NOTE: The default mode std::ios::in | std::ios::out is different from the default for std::fstream, which is std::ios::out only. This is for backwards compatibility with earlier POCO versions.

## Destructor

### ~FileStream

~FileStream() override;

Destroys the FileOutputStream.

## Member Functions

### open

void open(
const std::string & path,
std::ios::openmode mode = std::ios::out | std::ios::in
) override;

Opens the file specified by path, using the given mode.

Throws a FileException (or a similar exception) if the file does not exist or is not accessible for other reasons and a new file cannot be created.

See also: Poco::FileIOS::open()