Your output is writen to the file named fileName
replace
PrintWriter writer = new PrintWriter("fileName");
with
PrintWriter writer = new PrintWriter(fileName);
EDIT:
Apparenttly you are just not looking for the file in wrong place, add the following statement to see where it has bee created:
System.out.println(new File(fileName).getAbsolutePath());
Also note that the order of close
, flush
is not correct. flush
should be called first.