Write Stream<String> to a file?
Sam Pullara
spullara at gmail.com
Tue Nov 19 19:27:22 PST 2013
My solution seems the right way to go and is basically a mirror of that method. It should probably have an override that takes a stream rather than just an Iterable to make it more obvious. Here is the form with all the static imports:
Stream<String> s = Files.lines(get(from), UTF_8);
Files.write(get(to), s::iterator, UTF_8);
Sam
On Nov 19, 2013, at 6:24 PM, Zhong Yu <zhong.j.yu at gmail.com> wrote:
> A problem with this is that most write() methods in java.io throw
> checked IOException. PrintWriter does not throw checked exceptions -
> it swallows them which is not good either.
>
> On Tue, Nov 19, 2013 at 6:47 PM, Brian Goetz <brian.goetz at oracle.com> wrote:
>> How about:
>>
>> stream.forEachOrdered(writer::write);
>>
>>
>> On 11/19/2013 6:19 PM, Zhong Yu wrote:
>>>
>>> We have convenience methods to read lines from a file:
>>> Stream<String> Files.lines()
>>>
>>> What's Java's idiomatic way to write a Stream<String> to a file?
>>>
>>> Zhong Yu
>>>
>>
>
More information about the lambda-dev
mailing list