O'Reilly logo

Java Programming for Beginners by Mark Lassoff

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required