| | |
I/O : simple but not yet solved
![]() |
•
•
Join Date: Oct 2004
Posts: 29
Reputation:
Solved Threads: 0
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:
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
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:
Java Syntax (Toggle Plain Text)
import java.io.*; //Serve per l'input e l'output su file public class ContoC{ public static void main(String args[]) throws IOException { String choice, temp; FileWriter fw; System.out.println(" CONTO CORRENTE "); System.out.println(); System.out.println("Insercisci il numero del I conto corrente:"); int a=0; BufferedReader in = new BufferedReader (new InputStreamReader (System.in)); try { a=Integer.parseInt(in.readLine()); }catch (IOException e){} //Input I conto System.out.println("Insercisci il numero del II conto corrente:"); int b=0; BufferedReader in1 = new BufferedReader (new InputStreamReader (System.in)); try { b=Integer.parseInt(in1.readLine()); }catch (IOException e){} //Input II conto System.out.println("Insercisci il numero del III conto corrente:"); int c=0; BufferedReader in2 = new BufferedReader (new InputStreamReader (System.in)); try { c=Integer.parseInt(in2.readLine()); }catch (IOException e){} //input III conto System.out.println(); ContoCorrente c1, c2, c3; c1=new ContoCorrente(a); c2=new ContoCorrente(b); c3=new ContoCorrente(c); c1.versamento(10000); c2.versamento(600); c3.versamento(5000); c1.prelievo(5000); c2.prelievo(100); c3.prelievo(2000); System.out.println("Saldo CC n." + c1.n_conto() +" --> " + c1.saldo()); System.out.println("Saldo CC n." + c2.n_conto() +" --> " + c2.saldo()); System.out.println("Slado CC n." + c3.n_conto() +" --> " + c3.saldo()); System.out.println(); c1.stampa(a); System.out.println(); c2.stampa(b); System.out.println(); c3.stampa(c); System.out.println(); // Qui inizia la parte di gestione output carattere (-> conti.txt) System.out.println("\n\nVuoi scrivere i dati sul file «conti.txt» ?\n"); BufferedReader in3 = new BufferedReader (new InputStreamReader (System.in)); try { fw = new FileWriter("conti.txt"); } catch(IOException exc) { System.out.println("Errore: il file non si apre!"); return ; } do { System.out.print(": "); choice = in3.readLine(); if(choice.compareTo("N") == 0) break; temp = "Conto: " + c1.n_conto() + " - Saldo: " + c1.saldo() + "\r\n"; fw.write(temp); temp = "Conto: " + c2.n_conto() + " - Saldo: " + c2.saldo() + "\r\n"; fw.write(temp); temp = "Conto: " + c3.n_conto() + " - Saldo: " + c3.saldo() + "\r\n"; fw.write(temp); } while(choice.compareTo("N") !=0); fw.close(); } }
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
![]() |
Similar Threads
- VB/MS Access Issue (Visual Basic 4 / 5 / 6)
- PCI Simple Communication Controller (Windows NT / 2000 / XP)
- compiler from microjava to java....NEED HELP (Java)
- on a simple airline booking program (C)
- How do you do a simple POS in VB .net (VB.NET)
- Recursion (C++)
Other Threads in the Java Forum
- Previous Thread: File I/O
- Next Thread: can't resolve error
| Thread Tools | Search this Thread |
-xlint android api applet application array arrays automation bi binary blackberry block bluetooth chat class client code compile compiler component converter database developmenthelp eclipse error fractal freeze functiontesting game gameprogramming givemetehcodez graphics gui health html ide image input int integer j2me j2seprojects java javac javaprojects jetbrains jni jpanel jtable julia learningresources lego linux list login loop loops mac main map method methods mobile myregfun netbeans newbie nonstatic notdisplaying number online problem program programming project qt recursion scanner screen server set singleton sms sort spamblocker sql string swing system textfields thread threads time title tree tutorial-sample update variablebinding windows working xor





