• Post Reply Bookmark Topic Watch Topic
  • New Topic

Basic I/O: PrintWriter

 
Sanjit Singh
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I have a very basic I/O question concerning PrintWriter. I am basically new to JAVA, so any help would be appreciated.
I have a method:
public void onResponseSent(PrintWriter writer){
}
How can I call this method?. My main aim is to transfer the contents of an XML file from one class to this class using the above method. In this method then I want to manipluate the contents of the XML document. How can I achieve this?
I can only use the above method, so any helpful code would be appreciated.
As you can see, its a stupid q, but hopefully somebody can help me out. Thanks!
 
Sam Moran
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The newxml file is either a local file or a URL:
BufferedReader in = new BufferedReader(new InputStreamReader(newxml));
PrintWriter xmlout = new PrintWriter(new FileOutputStream(xmlfile));
String l;
for( l = null; (l = in.readLine()) != null; ) {
xmlout.println(l);
}
xmlout.close();
I hope this helps!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!