Re: Question: XML file communication between server and client
Fengyuan wrote:
Thank you for the reply. How can I read each line from my XML file
into the client and then send to the server? Do I need XML parser at
client side or the parser at server side? I am new to Java, hopefully
someone can help me out. Thanks
To read a line from a file, use something like this:
BufferedReader fin = new BufferedReader(new FileReader("filename.xml"));
String line = fin.readLine();
To write this line to the server, use:
out.println(line);
The easiest way to send an entire file this way is to use this loop:
BufferedReader fin = new BufferedReader(new FileReader("filename.xml"));
String line;
while ((line = fin.readLine()) != null) {
out.println(line);
}
If you want to parse the XML file, then yes, you will need to use an XML
parser at the server side (but not the client).
For further information, refer to the javadocs at
http://java.sun.com/j2se/1.5.0/docs/api/index.html or
http://java.sun.com/j2se/1.4.2/docs/api/index.html depending on your
version.