Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #35829

Re: How do you close the stream with Files.write?

From Eric Sosman <esosman@comcast-dot-net.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: How do you close the stream with Files.write?
Date 2016-10-19 17:07 -0400
Organization A noiseless patient Spider
Message-ID <nu8n9u$mbu$1@dont-email.me> (permalink)
References <nu8mjm$jhh$1@dont-email.me>

Show all headers | View raw


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.

-- 
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


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