java - why doesnt my printWriter work ? -


im not sure why isnt working, ive tried can on it. feel im close getting right cant last few things set together. realise not coded beginner @ , appreciate can get.

        public void actionperformed(actionevent event) {         object source = event.getsource();         object flight = airlinesbox.getselecteditem();         object departurelocation = locationsbox.getselecteditem();         object destination = destinationbox.getselecteditem();         object returnorsingle = typeofflightbox.getselecteditem();         object flightdate = datebox.getselecteditem();         object flighttime = timebox.getselecteditem();         object flightseat = classofseatbox.getselecteditem();         object flightbag = flightbagbox.getselecteditem();         object flightmeal = flightmealbox.getselecteditem();            if(source == printticket)         {              try {                 printwriter write = new printwriter("receipt.txt");                 write.println("_______________________________________");                 write.println("|                                      |");                 write.println("|   --------------------------------   |");                 write.println("|   |  flight receipt |   |");                 write.println("|   |      please keep safe     |   |");                 write.println("|   --------------------------------   |");                 write.println("|                                      |");                 write.println("|   --------------------------------   |");                 write.println("|   |                              |   |");                 write.println("     airline= " + flight);                 write.println("     departure location= " + departurelocation);                 write.println("     destination= " + destination);                 write.println("     flight type= " + returnorsingle);                 write.println("     flight day= " + flightdate);                 write.println("     flight time= " + flighttime);                 write.println("     flight seat type= " + flightseat);                 write.println("     bags= " + flightbag);                 write.println("     flight meal= " + flightmeal);                 write.println("|   |                              |   |");                 write.println("|   --------------------------------   |");                 write.println("----------------------------------------");                  write.close();                    system.out.println(airlinesbox.getselecteditem());                 system.out.println(locationsbox.getselecteditem());                 system.out.println(destinationbox.getselecteditem());                 system.out.println(typeofflightbox.getselecteditem());                 system.out.println(datebox.getselecteditem());                 system.out.println(timebox.getselecteditem());                 system.out.println(classofseatbox.getselecteditem());                 system.out.println(flightbagbox.getselecteditem());                 system.out.println(flightmealbox.getselecteditem());                  }              catch (filenotfoundexception e)              {                 // todo auto-generated catch block                 e.printstacktrace();             }              } 

printwriter has nasty habit of hiding errors you. recommend swapping read/write class. please take following information on bufferedwriter. or if stuck printwriter, how check errors.

http://www.mkyong.com/java/how-to-write-to-file-in-java-bufferedwriter-example/

be aware, have add newline characters bufferedreader since doesn't have println method. little detail on differences check out post.

difference between java.io.printwriter , java.io.bufferedwriter?


Comments

Popular posts from this blog

android - Pass an Serializable object in AIDL -

How to provide Authorization & Authentication using Asp.net, C#? -

How to use Authorization & Authentication in Asp.net, C#? -