Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #35831
| From | Knute Johnson <nospam@rabbitbrush.frazmtn.com> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: How do you close the stream with Files.write? |
| Date | 2016-10-19 16:12 -0500 |
| Organization | A noiseless patient Spider |
| Message-ID | <nu8njs$niq$1@dont-email.me> (permalink) |
| References | <nu8mjm$jhh$1@dont-email.me> <nu8n9u$mbu$1@dont-email.me> |
On 10/19/2016 16:07, Eric Sosman wrote: > On 10/19/2016 4:55 PM, Knute Johnson wrote: >> java.nio.file.Files(Path path, Iterable<? extends CharSequence> lines, >> OpenOption... options) appears to have no way to close the underlying >> stream? > > (I guess there's a `write' missing before the parameters.) > > Looks like the file auto-closes at the end of the operation. From > the JavaDoc for the three-parameter write(): > > This method works as if invoking it were equivalent to > evaluating the expression: > > Files.write(path, lines, StandardCharsets.UTF_8, options); > > ... and the JavaDoc for the latter says > > [...] The method ensures that the file is closed when all lines > have been written (or an I/O error or other runtime exception > is thrown). [...] > > So it appears you're only in trouble if you want the stream > to remain open. > Thanks Eric, I missed that as I was looking at the docs for the other write method. I did look in the source and it is clearly closed there. -- Knute Johnson
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar | Unroll thread
How do you close the stream with Files.write? Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2016-10-19 15:55 -0500
Re: How do you close the stream with Files.write? Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-10-19 17:07 -0400
Re: How do you close the stream with Files.write? Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2016-10-19 16:12 -0500
csiph-web