In Java, I have text from a text field in a String variable called \"text\".
How can I save the contents of the \"text\" variable to a file?
Use FileUtils.writeStringToFile() from Apache Commons IO. No need to reinvent this particular wheel.
FileUtils.writeStringToFile()