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:

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

hi
if you can attach all the related files i can compile and see what happens.
Regards
Srinivas

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.