FileIO.toPath
Create a sink which will write incoming ByteString s to a given file path.
Signature
Description
Creates a Sink which writes incoming ByteString elements to the given file path. Overwrites existing files by truncating their contents as default. Materializes a Future CompletionStage of IOResult. On success, the count is the number of bytes written by this stream, not the total file size. If the channel cannot make progress while writing a nonempty element, the stream fails instead of returning a partial success.
Example
- Scala
-
source
val file = Paths.get("greeting.txt") val text = Source.single("Hello Pekko Stream!") val result: Future[IOResult] = text.map(t => ByteString(t)).runWith(FileIO.toPath(file)) - Java
-
source
final Path file = Paths.get("greeting.txt"); Sink<ByteString, CompletionStage<IOResult>> fileSink = FileIO.toPath(file); Source<String, NotUsed> textSource = Source.single("Hello Pekko Stream!"); CompletionStage<IOResult> ioResult = textSource.map(ByteString::fromString).runWith(fileSink, system);
2.1.0-M0+55-7bef0438*