Computer Science Canada Urgent: Output and loop |
Author: | IntelMaster [ Sun Jun 06, 2010 10:29 am ] |
Post subject: | Urgent: Output and loop |
[code try { String file=jTextField12.getText(); DataOutput f=new DataOutputStream(new FileOutputStream(file+".txt")); f.writeBytes("Answers"); for (int output=0; output<count1; output++) f.writeBytes(count1+"="+answer1[count1]); } catch (Exception e) { String msg=e.toString (); } // TODO add your handling code here: } ] For some reason this program isn't working |
Author: | TheGuardian001 [ Sun Jun 06, 2010 7:01 pm ] |
Post subject: | Re: Urgent: Output and loop |
Can you be more specific? What exactly do you mean when you say "For some reason it doesn't work"? Does the program give an error message? Is it not outputting anything at all, or is it just outputting wrong? It would probably help to see what the problem is if you gave a full program, instead of a chunk of code that can't be run on its own. |
Author: | Unnamed.t [ Sun Jun 06, 2010 7:44 pm ] |
Post subject: | Re: Urgent: Output and loop |
TheGuardian001 wrote: Can you be more specific? What exactly do you mean when you say "For some reason it doesn't work"?
Yup, I agree. For all we know your program could just have some stupid mistake like the method not throwing an IOException or forgeting to import a class or... (u know wut I mean) It could help a lot if you can copy and paste your code from top to bottom of the whole file. |
Author: | Zren [ Sun Jun 06, 2010 8:35 pm ] |
Post subject: | RE:Urgent: Output and loop |
You have to close IO streams before it actually writes anything to file in java. |
Author: | DemonWasp [ Mon Jun 07, 2010 12:21 am ] |
Post subject: | RE:Urgent: Output and loop |
Alternately, you can call .flush() on them to force them to write - this is actually done as part of the close() operation. |