-2

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!

2 Answers2

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