Results 1 to 3 of 3
Thread: What is wrong?
- 02-02-2011, 05:02 PM #1
Member
- Join Date
- Nov 2010
- Posts
- 8
- Rep Power
- 0
What is wrong?
I am trying to print this to a file:
Whenever i print it to the file, i getJava 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++){ Tracks[t]=(Newtrack); duration[t]=(Newtime); outfile.println(Tracks[t] + "," + duration[t]+ ","); t++; } outfile.close(); }
title,singer,price,category,discount,track1,time1
title,singer,price,category,discount,track2,time2
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
- 02-02-2011, 06:06 PM #2
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 - Play indie games, learn from game tutorials and source code, upload your own games!
- 02-02-2011, 06:08 PM #3
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
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
-
What am I doing wrong?
By yankeefan9874 in forum New To JavaReplies: 1Last Post: 04-16-2010, 08:54 AM -
Wrong output (well.. the one who's wrong is probably me ;) )
By shacht1 in forum New To JavaReplies: 2Last Post: 11-22-2009, 03:48 PM -
what am i doing wrong here??
By tornbacchus in forum New To JavaReplies: 19Last Post: 04-16-2009, 03:54 AM -
what's wrong?
By rayda in forum New To JavaReplies: 3Last Post: 04-14-2009, 09:07 PM -
what wrong
By pro85 in forum New To JavaReplies: 3Last Post: 02-09-2009, 01:07 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks