I/O : simple but not yet solved

Reply

Join Date: Oct 2004
Posts: 29
Reputation: trashed is an unknown quantity at this point 
Solved Threads: 0
trashed trashed is offline Offline
Light Poster

I/O : simple but not yet solved

 
0
  #1
Oct 21st, 2005
hi.
my problem is plain simple but still i couldn't make it out.
it's all very basic stringwork (keyboard input, println, ...) but when I get to the point of writing the output file, nothing happens: the text file is created but remain completely blank.
this is my code:

  1. import java.io.*; //Serve per l'input e l'output su file
  2.  
  3.  
  4.  
  5. public class ContoC{
  6.  
  7.  
  8.  
  9. public static void main(String args[]) throws IOException {
  10.  
  11.  
  12.  
  13. String choice, temp;
  14. FileWriter fw;
  15.  
  16. System.out.println(" CONTO CORRENTE ");
  17.  
  18. System.out.println();
  19.  
  20.  
  21.  
  22. System.out.println("Insercisci il numero del I conto corrente:");
  23.  
  24. int a=0;
  25.  
  26. BufferedReader in = new BufferedReader (new InputStreamReader (System.in));
  27.  
  28. try {
  29.  
  30. a=Integer.parseInt(in.readLine());
  31.  
  32. }catch (IOException e){} //Input I conto
  33.  
  34.  
  35.  
  36. System.out.println("Insercisci il numero del II conto corrente:");
  37.  
  38. int b=0;
  39.  
  40. BufferedReader in1 = new BufferedReader (new InputStreamReader (System.in));
  41.  
  42. try {
  43.  
  44. b=Integer.parseInt(in1.readLine());
  45.  
  46. }catch (IOException e){} //Input II conto
  47.  
  48.  
  49.  
  50. System.out.println("Insercisci il numero del III conto corrente:");
  51.  
  52. int c=0;
  53.  
  54. BufferedReader in2 = new BufferedReader (new InputStreamReader (System.in));
  55.  
  56. try {
  57.  
  58. c=Integer.parseInt(in2.readLine());
  59.  
  60. }catch (IOException e){} //input III conto
  61.  
  62.  
  63.  
  64. System.out.println();
  65.  
  66.  
  67.  
  68. ContoCorrente c1, c2, c3;
  69.  
  70.  
  71.  
  72. c1=new ContoCorrente(a);
  73.  
  74. c2=new ContoCorrente(b);
  75.  
  76. c3=new ContoCorrente(c);
  77.  
  78.  
  79.  
  80. c1.versamento(10000);
  81.  
  82. c2.versamento(600);
  83.  
  84. c3.versamento(5000);
  85.  
  86.  
  87.  
  88. c1.prelievo(5000);
  89.  
  90. c2.prelievo(100);
  91.  
  92. c3.prelievo(2000);
  93.  
  94.  
  95.  
  96. System.out.println("Saldo CC n." + c1.n_conto() +" --> " + c1.saldo());
  97.  
  98. System.out.println("Saldo CC n." + c2.n_conto() +" --> " + c2.saldo());
  99.  
  100. System.out.println("Slado CC n." + c3.n_conto() +" --> " + c3.saldo());
  101.  
  102.  
  103.  
  104. System.out.println();
  105.  
  106. c1.stampa(a);
  107.  
  108. System.out.println();
  109.  
  110. c2.stampa(b);
  111.  
  112. System.out.println();
  113.  
  114. c3.stampa(c);
  115.  
  116. System.out.println();
  117.  
  118. // Qui inizia la parte di gestione output carattere (-> conti.txt)
  119.  
  120. System.out.println("\n\nVuoi scrivere i dati sul file «conti.txt» ?\n");
  121.  
  122. BufferedReader in3 = new BufferedReader (new InputStreamReader (System.in));
  123.  
  124. try { fw = new FileWriter("conti.txt"); }
  125.  
  126. catch(IOException exc) {
  127. System.out.println("Errore: il file non si apre!");
  128. return ;
  129. }
  130. do {
  131. System.out.print(": ");
  132. choice = in3.readLine();
  133. if(choice.compareTo("N") == 0) break;
  134.  
  135. temp = "Conto: " + c1.n_conto() + " - Saldo: " + c1.saldo() + "\r\n";
  136. fw.write(temp);
  137. temp = "Conto: " + c2.n_conto() + " - Saldo: " + c2.saldo() + "\r\n";
  138. fw.write(temp);
  139. temp = "Conto: " + c3.n_conto() + " - Saldo: " + c3.saldo() + "\r\n";
  140. fw.write(temp);
  141.  
  142. } while(choice.compareTo("N") !=0);
  143.  
  144. fw.close();
  145.  
  146. }
  147.  
  148. }

for debugging i added 3 System.out.println to check the temp string and it was ok.
the only problem seems to be writing on the file
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 45
Reputation: cheenu78 is an unknown quantity at this point 
Solved Threads: 0
cheenu78's Avatar
cheenu78 cheenu78 is offline Offline
Light Poster

Re: I/O : simple but not yet solved

 
0
  #2
Oct 21st, 2005
hi
if you can attach all the related files i can compile and see what happens.
Regards
Srinivas
We come to love not by finding a perfect person, but by learning to see an imperfect person perfectly.

-Sam Keen, from To Love and Be Loved
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC