import java.io.*; public class ExampleSaveToFile { public static void main(String[] args) throws IOException { String exampleString = "I hope this string writes to a file!"; // read bytes until eof try { FileOutputStream outfile = new FileOutputStream("myoutfile.txt"); for (int i = 0; i < exampleString.length(); i++) { outfile.write((int)exampleString.charAt(i)); } outfile.close(); } catch(IOException e) { System.err.println("Could not read from myoutfile.txt"); } System.out.println("Hopefully this wrote to some file: " + exampleString); } }