1

I'm new and I have a question. How can I close a file in java using functional programming(using lambda)?

How can I convert for example file.close() into something that looks in a functional manner?

Cipri
  • 15
  • 1
  • 6
  • 2
    What's wrong with file.close()? – xs0 Nov 18 '17 at 11:28
  • try to read this http://winterbe.com/posts/2015/03/25/java8-examples-string-number-math-files/ the second paragraph before last paragraph. – Maytham Fahmi Nov 18 '17 at 11:34
  • @xs0 i need a functional manner for the faculty,i already use the function close() – Cipri Nov 18 '17 at 11:40
  • if the duplicate I've suggested doesn't answer your question then keep following the duplicates of each post and eventually you'll find what you're looking for. – Ousmane D. Nov 18 '17 at 11:43
  • Can you explain what you mean with "functional manner"? Maybe with some example of the same code in "non-functional manner" and then also in "functional manner", so that we can understand the difference.. (the way I understand functional, your original question makes no sense) – xs0 Nov 18 '17 at 11:44

1 Answers1

0

The closest you can get to clean the 'close a resource' is try with resources (But thats not functional..):

try (BufferedReader br = new BufferedReader(new FileReader("myfile")){

    } catch (IOException e) {
        e.printStackTrace();
    }
ian1095
  • 551
  • 4
  • 8