Java writing to xml Simple problem?(code included)
Here is my problem, in my Java applet i got this textfield(txtNormalHours) and button(xml).
When I press this button program should create file foo.xml, but nothing happens, no errors.
Here is the funny part without that button code works fine and foo.xml is created so I think there is something wrong in my main program code?
I cannot figure what´s wrong.... If someone could tell me what to do.
Offcourse if there is easier way to write in to xml file please tell.
main program code:
Code:
void button_actionPerformed(ActionEvent e) {
if(e.getActionCommand().equals("xml"))
{
String norm = txtNormalHours1.getText(); //get information from textfield
FOO f1 = new FOO();
f1.setFoo(norm);
try {
FooHelper.write(f1, "foo.xml");
} catch (Exception ex)
{ ex.printStackTrace();
}
}
}
FooHelper code:
Code:
package simple;
import java.beans.XMLEncoder;
import java.beans.XMLDecoder;
import java.io.*;
public class FooHelper {
public static void write(FOO f, String filename) throws Exception{
XMLEncoder encoder =
new XMLEncoder(
new BufferedOutputStream(
new FileOutputStream(filename)));
encoder.writeObject(f);
encoder.close();
}
}
FOO code:
Code:
package simple;
public class FOO {
private String foo ;
public void setFoo(String s) {
foo = s;
}
public String getFoo() {
return foo;
}
}
Re: Java writing to xml Simple problem?(code included)
Quote:
Originally posted by hiisikukko
my Java applet ... should create file foo.xml, but nothing happens, no errors.
applets cannot create files..