The FileWriter class

The FileWriter class and its usage could be explained as follows:

  1. Let's declare a new FileWriter class, and for reasons that will become apparent a little later on, let's explicitly set this FileWriter class to null:
        public class WritingToFiles { 
            public static void main(String[] args) { 
                FileWriter out = null; 
  1. Once we do this, we can go ahead and instantiate it. In order to write to a file, we're going to need to know two important things:
    • First, of course, we'll need to know what to write to the file
    • Second, our FileWriter class will need to know what file it should write to
  1. When we use a FileWriter class, we associate it with a specific file, so we pass into its constructor the name of the file we would like ...

Get Java Programming for Beginners now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.