FileIO.fromPath
Emits the contents of a file from the given path.
File IO Sinks and Sources
Signature
def fromPath ( f : Path , chunkSize : Int = 8192 ): Source [ ByteString , Future [ IOResult ]]
def fromPath ( f : Path , chunkSize : Int , startPosition : Long ): Source [ ByteString , Future [ IOResult ]]
Description
Emits the contents of a file from the given path, as ByteString
s, materializes into a Future
CompletionStage
which will be completed with a IOResult
upon reaching the end of the file or if there is a failure.
Example
Scala
copy source import akka . stream . scaladsl . _
val file = Paths . get ( "example.csv" )
val foreach : Future [ IOResult ] = FileIO . fromPath ( file ). to ( Sink . ignore ). run ()
Java
copy source final Path file = Paths . get ( "example.csv" );
Sink < ByteString , CompletionStage < Done >> printlnSink =
Sink .< ByteString > foreach ( chunk -> System . out . println ( chunk . utf8String ()));
CompletionStage < IOResult > ioResult = FileIO . fromPath ( file ). to ( printlnSink ). run ( mat );
Found an error in this documentation? The source code for this page can be found
here .
Please feel free to edit and contribute a pull request.