• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with writing the file

 
trinadh reddy
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i havv to write to the file that deletes the old contents of the file and writes the new data.but the writing is performed by appending to old data in the file

TransformerFactory tFactory = TransformerFactory.newInstance();

Transformer transformer = tFactory.newTransformer();

DOMSource source = new DOMSource(rootNode);
FileOutputStream fos= new FileOutputStream("D:/jspp/web.xml");
fos.flush();
StreamResult result = new StreamResult(fos);
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15482
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could try deleting the file before you open it for writing:
 
trinadh reddy
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have triedlike this also but no use it is appending to old data.that file is not deleting
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does the delete() method return true?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, where exactly did this "rootNode" come from? Is it possible that this node actually has all the old data still attached to it? (Plus whatever new data you've added?) That would be my guess at this point. The way you're creating the FileOutputStream, it shouldn't matter whether you delete the old file or not - you're overwriting it. If you're seeing the old data appear again, it's probably because you're actually writing it again. Which could be because it's still attached to the rootNode.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic