October 2017
Beginner
318 pages
7h 26m
English
Unfortunately, when we open up out.txt, there's nothing for us to see. This leads us to believe that our file writing probably didn't work. So what went wrong? Well, there's an important piece to using a FileWriter that we failed to take into account. When our FileWriter is created, it opens a file, and whenever we open a file, we should make sure that we close it in the end. This is pretty easy to do from a code standpoint; we simply call the close method on our FileWriter:
public class WritingToFiles { public static void main(String[] args) { FileWriter out = null; try{ out = new FileWriter("out.txt"); for(long number : FibonacciNumbers()) { out.write(String.valueOf(number)); // System.out.println(number); ...Read now
Unlock full access