java - 'try with resource' feature for File class -
i have 1 scenario trying implement java 7 'try resource' feature.
my block contains object of bufferedwriter
, file
, want close using 'try resource' feature, instead of closing calling close method explicitly.
but checked on net , saw file
class not implement autocloseable
interface, bufferedwriter
does. how can manage scenario implement 'try resource' feature?
try (bufferedwriter br = new bufferedwriter(new filewriter(path)))
use simply, br closed automatically. eg. http://www.roseindia.net/java/beginners/java-write-to-file.shtml
Comments
Post a Comment