Search code examples
javaswingfile-iojtextfieldjtextarea

How to save content from a JTextField into a file


I am doing a project where i am inputting recipes and their corresponding info, (title, ingredients, utilities, directions) in a JFrame, and then i want to save that content to a file. The fields where the user inputs the data are(title,ingredients etc.) and they are JTextFields. What i need to know is how the text from that JTextField can be written to a new file. I would prefer that each field has its own file, so the title of the recipe alone would have its own file, e.g stirfry.txt, and then the content would be "stirfry"

Any feedback would be much appreciated


Solution

  • Get the content of your textfield using the getText() function Create a new file using java.io and write the content of the file using a BufferedStream.