What I have to do at java:
try(InputStream inputStream = new FileInputStream("/home/user/123.txt")) {
byte[] bytes = new byte[inputStream.available()];
inputStream.read(bytes);
System.out.println(new String(bytes));
} catch (IOException e) {
e.printStackTrace();
}
But kotlin
doesn't know about try-with-resources
! So my code is
try {
val input = FileInputStream("/home/user/123.txt")
} finally {
// but finally scope doesn't see the scope of try!
}
Is there an easy way to close the stream ? And I don't speak only about files. Is there a way to close any stream
easily ?