Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #38861
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Does this make sense? |
| Date | 2019-04-04 09:03 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <q84vam$lri$1@dont-email.me> (permalink) |
| References | <f9818c55-5eb6-47f8-8ec9-d512861ddee7@googlegroups.com> |
On 4/4/2019 8:22 AM, Eric Douglas wrote:
> Trying to avoid Eclipse compile warnings I end up with code like this.
>
> FileOutputStream fos = null;
> try {
> fos = new FileOutputStream(myFile);
> fos.write(myByteArray);
> } catch (IOException e) {
> e.printStackTrace();
> } finally {
> try {
> fos.close();
Aside: I think you need a null-test here.
> } catch (IOException e) {
> e.printStackTrace();
> }
> }
Consider try-with-resources:
try (FileOutputStream fos = new FileOutputStream(myFile)) {
fos.write(myByteArray);
} catch (IOException e) {
e.printStackTrace(); // a stopgap, at best
}
It's not quite equivalent (see "suppressed exception"), but it's
pretty close.
--
esosman@comcast-dot-net.invalid
Six hundred fifty-seven days to go.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Does this make sense? Eric Douglas <e.d.programmer@gmail.com> - 2019-04-04 05:22 -0700
Re: Does this make sense? Eric Sosman <esosman@comcast-dot-net.invalid> - 2019-04-04 09:03 -0400
Re: Does this make sense? Eric Douglas <e.d.programmer@gmail.com> - 2019-04-04 07:02 -0700
Re: Does this make sense? Eric Sosman <esosman@comcast-dot-net.invalid> - 2019-04-04 11:01 -0400
Re: Does this make sense? Eric Douglas <e.d.programmer@gmail.com> - 2019-04-04 08:21 -0700
Re: Does this make sense? Eric Douglas <e.d.programmer@gmail.com> - 2019-04-04 11:45 -0700
Re: Does this make sense? Arne Vajhøj <arne@vajhoej.dk> - 2019-04-04 20:33 -0400
Re: Does this make sense? Eric Douglas <e.d.programmer@gmail.com> - 2019-04-05 08:39 -0700
Re: Does this make sense? Arne Vajhøj <arne@vajhoej.dk> - 2019-04-05 12:31 -0400
Re: Does this make sense? bursejan@gmail.com - 2019-04-05 10:53 -0700
Re: Does this make sense? bursejan@gmail.com - 2019-04-05 10:57 -0700
Re: Does this make sense? bursejan@gmail.com - 2019-04-05 11:02 -0700
Re: Does this make sense? bursejan@gmail.com - 2019-04-05 11:13 -0700
Re: Does this make sense? Patrick Roemer <sangamon@netcologne.de> - 2019-04-05 17:43 +0200
Re: Does this make sense? Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2019-04-07 22:14 +0200
Re: Does this make sense? Andreas Leitgeb <avl@logic.at> - 2019-04-04 15:15 +0000
csiph-web