Writing to a file in Java can be done as follows:

 try {
   
    BufferedWriter out = new BufferedWriter(
        new FileWriter("outfilename"));

    out.write("aString");
    out.close();

} catch (IOException e) {
    e.printStackTrace();
}