i have a TextField in myGUI where some data(results) are shown after calculation. I have a 'save' button to save this result into a particular txt file..

i almost done without error....but inside my txt file it shows this kind of things:


Please anybody help me to figure out...

else if (e.getSource()==saveButton){
 int x=Integer.parseInt(inputField.getText());
 String str=Integer.toString(x*x);
       try {
// String selection =selection.getSelectedText();
  String selection=resultField.getText();
  StringSelection data= new StringSelection(selection);
File outFile= new File("c:/Java/math.txt");
FileOutputStream fos=new FileOutputStream(outFile);
PrintWriter pr=new PrintWriter(fos);


catch (IOException ioe) {	

Why do you need a StringSelection Object? You should just need the String, i.e. the one that is stored in your variable called 'selection'.

Btw, the error is that you're using PrintWriter's "print" method, and you are passing it a StringSelection Object. But if you look at the class documentation for PrintWriter, no such method exists. However, PrintWriter does have a method that takes a String, so you should get rid of the StringSelection variable and do:


^ Here is the PrintWriter javadoc, take a look. No "print" method exists that takes a StringSelection Object as a param.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.