The FileWriter class and its usage could be explained as follows:
- 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;
- 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
- 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 ...