-2

I am currently trying to write a java program that has a nice UI that asks for three inputs from the user, Name, Project ID, Hours, and Date. I am using this to track my progress at work on all the projects I am currently working on. I have some java experience but I am still learning. So what I am trying to accomplish is create a program that takes the users input and prints a report to a text file. I have the fields set up and I have most of the interface set up how I want it. However I would like to have a button that prints what the user input to a text file. How do I do this? How do I go about taking the users input and printing to a text file? I would really appreciate any suggestions. Thanks in advance!

Mike
  • 19
  • 1
  • 4
  • http://stackoverflow.com/a/1625263/16959 <- this is a single answer to the sub question, how to append to a file in Java. As for "have a button that", how far have you gotten? – Jason Sperske May 03 '13 at 21:03
  • This question will be closed soon... is just too vague. For the UI read about java swing and for writing to a text file use FileOutputStream. Try to be more specific when asking in stackoverflow. – rsan May 03 '13 at 21:06

1 Answers1

3

To print to a file, use the following:

PrintWriter fout = new PrintWriter(new FileWriter("file_name.txt", true));

You can use fout just like System.out. Make sure to call fout.close() when you're done writing. The true in the constructor specifies that you want to append to the file; to overwrite the file, change it to false (thanks Jason).

Taking user input is a different question and the answer depends on how your interface is structured.

nullptr
  • 2,244
  • 1
  • 15
  • 22