'try catch' reconstruction from java 1.7 to java 1.6 -



'try catch' reconstruction from java 1.7 to java 1.6 -

i using jar file other person, need add together source codes in project , compile them when import such packages. issue jar file seems generated java1.7 uses java1.7 fetures. using java1.6. source codes:

public properties getdefaults() { seek (inputstream stream = getclass().getresourceasstream(property_file)) { properties properties = new properties(); properties.load(stream); homecoming properties; } grab (ioexception e) { throw new runtimeexception(e); } }

the eclipse gives such error hints:

resource specification not allowed here source level below 1.7

then how rewrite such codes can handled java1.6?

to re-write try-with-resource statement compatible java 1.6, following:

declare variable before try block begins. create variable @ top of try block. add finally block close resource.

example:

inputstream stream = null; seek { stream = getclass().getresourceasstream(property_file)); // rest of seek block same } // grab block same { if (stream != null) { seek { stream.close(); } grab (ioexception ignored) { } } }

java try-catch

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -