-3

I'm trying to write a program that writes a listing of things to a *.txt file, and everything appears to be all good and well but nothing is written in the txt file. Any help is appreciated. I won't post my code on here because it's only a small fraction, but I'm using a formatter in the form Formatter fileMaker = new Formatter("file.txt"); and then I would do something like fileMaker.format(%s, String str); but nothing turns up in the file? Thanks for the help.

Hopefully this little bit might help, maybe I'm doing something wrong that I don't see, but I declared it as private static Formatter fileMaker; in the class and then I implement it like below.

fileMaker.format("%s%d\n", "#flightCount", flights2.size());


    for(int i=0; i<flights2.size(); i++){
        fileMaker.format("%s %s%s%d%d %d ", "#newFlight", flights2.get(i).getSourceAirport(), flights2.get(i).getDestinationAirport(),
                flights2.get(i).getTakeoffTime(), flights2.get(i).getLandingTime(), flights2.get(i).getCapacity());
    }
Kick Buttowski
  • 6,709
  • 13
  • 37
  • 58

1 Answers1

0
PrintWriter fileWriter= new PrintWriter("my-file.txt");
fileWriter.println("Content");
fileWriter.close();
Anubian Noob
  • 13,426
  • 6
  • 53
  • 75
  • When I switched from Formatter to PrintWriter it said I had a NullPointerException which I don't understand why that happened, any thoughts? – Brendan Cameron Apr 20 '15 at 03:01
  • 1
    @BrendanCameron What? Do you mean that this code gave you a null pointer exception? Do you want to show us what you tried? – Anubian Noob Apr 20 '15 at 03:02