This function saves a simple file with the name "filename", which contains the message "hello world". java.io.* must be imported first. public boolean SaveTXTfile(String filename) { private FileOutputStream fout; private PrintWriter myOutput; // Saving the results on the file try { fout=new FileOutputStream(filename); myOutput=new PrintWriter(fout, true); myOutput.println("hello world"); } catch (IOException e) { return false; // Error occured } // Closing the text file try { myOutput.flush(); myOutput.close(); fout.flush(); fout.close(); } catch(IOException e) { return false; } return true; // Text file saved successfully }