I'm writing a program in netbeans 7.0.1 that is being used to store character sheets for D&D. I need to run it as just a executable jar so that my friends can use it as well. How do I go about adding the ability for it to save changes to the sheet? As in, save what the user types into the textfields? Thank you so much!
Asked
Active
Viewed 115 times
-2
-
2You got some sample code to share? Regards! – Mechkov Dec 01 '11 at 18:36
-
I have been using the gui builder so it auto-generates to code. (I'm a very new programer) What section of the code would be the most helpful? – Brian Orndorff Dec 01 '11 at 18:40
2 Answers
2
import java.io.*;
class FileWrite
{
public static void main(String args[])
{
try{
// Create file
FileWriter fstream = new FileWriter("out.txt");
BufferedWriter out = new BufferedWriter(fstream);
out.write("Hello Java"); <- here goes what is on the input fields
//Close the output stream
out.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
}

Nuno
- 1,163
- 1
- 11
- 15
1
If you are a very new programmer, I would encourage you to write a console version of the application first. Some relevant classes would be BufferedReader for getting user input, FileReader/FileWriter for reading/saving files. Some quick googling for "java read user input" and "java read write files" should be enough to get you started. Hope that helps.

jeff
- 4,325
- 16
- 27