Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #35831
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Knute Johnson <nospam@rabbitbrush.frazmtn.com> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: How do you close the stream with Files.write? |
| Date | Wed, 19 Oct 2016 16:12:47 -0500 |
| Organization | A noiseless patient Spider |
| Lines | 32 |
| Message-ID | <nu8njs$niq$1@dont-email.me> (permalink) |
| References | <nu8mjm$jhh$1@dont-email.me> <nu8n9u$mbu$1@dont-email.me> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Injection-Date | Wed, 19 Oct 2016 21:12:28 -0000 (UTC) |
| Injection-Info | mx02.eternal-september.org; posting-host="66689394d78afda5bc2d589e4b9a78cb"; logging-data="24154"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX180rf5x+WCSFZ8YmHtKA7Q6" |
| User-Agent | Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 |
| In-Reply-To | <nu8n9u$mbu$1@dont-email.me> |
| Cancel-Lock | sha1:nAoDApQN3jiYw6kHWZc9nRt9oC4= |
| Xref | csiph.com comp.lang.java.programmer:35831 |
Show key headers only | View raw
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