How to delete FileOutputStream ,once we are done with writting in it ?
public static void writeXmlFile( Document doc,InputStream input)
{
try {
XMLSerializer serializer = new XMLSerializer();
serializer.setOutputCharStream( new java.io.FileWriter(input.toString()));
serializer.serialize(doc);
TransformerFactory tFactory = TransformerFactory.newInstance();
File xsltFile=new File ("C:\\src-tgt-hgh\\src-tgt-hgh.xslt");
try{
if(xsltFile.exists()){
Transformer transformer = tFactory.newTransformer(new StreamSource(xsltFile));
transformer.transform( new StreamSource(input), new StreamResult(new FileOutputStream(OutStream)));
}
}
catch(FileNotFoundException e){
e.printStackTrace();
}
}catch (Exception ex) {
}
I am calling this method from main ,, once i write to file i want to delete that file
for that i am using
In main method
{
writeXmlFile(xmlDoc,instream);
if(OutStream.exists())
{
OutStream.delete();
}
}
But this seems to be not working Suggests solution !!!!!!!!!!!!! pLZZZZZZ
> I am calling this method from main ,, once i write to
> file i want to delete that file
Seems a bloody pointless exercise then!
For a stream i am passing file as input .. once work done i want to delete that input file passed to the FileOutputStream ..
It is not pointless i am already making use of that written file to disk .. once use is over i want to free that space ..
> For a stream i am passing file as input .. once work
> done i want to delete that input file passed to the
> FileOutputStream ..
Do that then. But streams don't need deleting
> It is not pointless i am already making use of that
> written file to disk .. once use is over i want to
> free that space ..
Then delete the file (after closing the stream) not the stream.
i am using .close () and closing both input as well as out put stream but it seem to be not working properly
> i am using .close () and closing both input as well
> as out put stream but it seem to be not working
> properly
It works perfectly. Maybe you should read the documentation to see what you're actually doing.
If people tell you you should delete the file, then you should delete the file and not try to do any magic on some stream. (Although yes, it needs to be closed. But just shutting the tap doesn't mean that the water tower disappears.)
Thanks a lot frens for u r help !!! I am able to delete file t after closing input and output streams ...
'frens' - friends
u r - your
!!! - .
... - .
i will keep that in mind !!!
Thanks frens !!!
Ooppss!!! Sorry !!! made mistake again ,, But u know it is harder to improve the perfection !!!!!
Improving perfection is pretty hard, I agree.
Thankfully, you're nowhere near it yet.
> i will keep that in mind !!!
> Thanks frens !!!
>
> Ooppss!!! Sorry !!! made mistake again ,, But u
> know it is harder to improve the perfection !!!!!
Here is the code i changed that works:
> Ooppss!!! Sorry !!! here is it:
Message was edited by:
deAppel
> > i will keep that in mind !!!
> > Thanks frens !!!
> >
> > Ooppss!!! Sorry !!! made mistake again ,, But u
> > know it is harder to improve the perfection
> !!!!!
>
> Here is the code i changed that works:
> > Ooppss!!! Sorry !!! here is it:
>
> Message was edited by:
> deAppel
where? :-) try editing that! :p
> > > i will keep that in mind !!!
> > > Thanks frens !!!
> > >
> > > Ooppss!!! Sorry !!! made mistake again ,, But u
> > > know it is harder to improve the perfection
> > !!!!!
> >
> > Here is the code i changed that works:
> > > Ooppss!!! Sorry !!! here is it:
> >
> > Message was edited by:
> > deAppel
>
> where? :-) try editing that! :p
For some reason i can't edit it anymore ;(
Anyway, i was trying to make clear that he shouldn't use exclamation mark like this !!!!!!! in every sentence.
mission failed i guess.
Anyway, if you check for the file with file f = new file();
and use a loop if the file exists you can delete it by: f.delete();
easy as that.
> Ooppss!!! Sorry !!! made mistake again
> For some reason i can't edit it anymore ;(
Yeh I know, I'm a l33t haxxor and I stopped you doing it :-)
(you can't edit a post once someone has replied to it)