But I would like to store the result in an external file. This file is created ok, but the result is not shown in the file.
What is wrong?
Thank you.
import java.util.*;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.math.*;
public class Addition {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int n = 5;
int k = 7;
int result = n+k;
System.out.println( + result );
try{
// Create file
FileWriter fstream = new FileWriter("calculation.txt");
BufferedWriter out = new BufferedWriter(fstream);
out.write(result);
//Close the output stream
out.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
}

New Topic/Question
Reply
MultiQuote






|