Results 1 to 3 of 3

Thread: What is wrong?

  1. #1
    phantom06 is offline Member
    Join Date
    Nov 2010
    Rep Power

    Default What is wrong?

    I am trying to print this to a file:
    Java Code:
            try {
            PrintWriter outfile = new PrintWriter(new FileWriter("CD.txt", true));
            outfile.println(title+","+singer+","+price+","+Category+","+discount + ",");
         for(int t=0;t<NumOfTracks;t++){
           outfile.println(Tracks[t] + "," + duration[t]+ ",");
    Whenever i print it to the file, i get

    I want it to be like this
    title,singer,price,category,discount,track1,time1, track2,time2.

    Why is it printing the same thing again and writting the track2 and time2 to it?

    Thank you

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Washington, DC
    Rep Power


    You don't really give us enough information to answer your question. What is (Newtrack) and (Newtime)? What is NumOfTracks?

    If you want help with code, make sure it's in SSCCE form. That doesn't mean post all of our code- it means narrow your code down to as few lines as possible while still being runnable and showing the problem.
    How to Ask Questions the Smart Way
    Static Void Games - GameDev tutorials, free Java and JavaScript hosting!
    Static Void Games forum - Come say hello!

  3. #3
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    New Zealand
    Rep Power


    The code you posted prints two lines (because there are two println() statements). These lines don't resemble either the output you want or the output you say you get.

    Also data is being appended to outfile, so the output you see may have come from different runs of the program.

    It might help if you posted a short compilable example that others can run to see the problem for themselves. It does not have to be long: just enough to illustrate the problem. Copy and post actual output from the program along what you would prefer the output to be,

Similar Threads

  1. Replies: 4
    Last Post: 06-11-2013, 01:37 AM
  2. What am I doing wrong?
    By yankeefan9874 in forum New To Java
    Replies: 1
    Last Post: 04-16-2010, 08:54 AM
  3. what am i doing wrong here??
    By tornbacchus in forum New To Java
    Replies: 19
    Last Post: 04-16-2009, 03:54 AM
  4. what's wrong?
    By rayda in forum New To Java
    Replies: 3
    Last Post: 04-14-2009, 09:07 PM
  5. what wrong
    By pro85 in forum New To Java
    Replies: 3
    Last Post: 02-09-2009, 01:07 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts