Project

Profile

Help

Bug #2250

closed

The output file cannot be deleted after executing an XSLT transformation

Added by Radu Pisoi almost 10 years ago. Updated over 8 years ago.

Status:
Closed
Priority:
Normal
Category:
JAXP Java API
Sprint/Milestone:
Start date:
2014-12-08
Due date:
% Done:

100%

Estimated time:
Legacy ID:
Applies to branch:
9.6, 9.7
Fix Committed on Branch:
9.6
Fixed in Maintenance Release:
Platforms:

Description

After I executed an XSLT transformation from a Java program the output file seems to be locked because it cannot be deleted.

The usual reason why this problem happens, is that the output stream over the file is not closed.

I can reproduce this issue from the next simple Java program with Saxon 9.6.0.3:

public static void main(String[] args) throws TransformerException, InterruptedException {
	// Create transformer
	File xslFile = new File(xslPath);
	InputSource inputSource = new InputSource(xslFile.toURI().toString());
	Source source = new SAXSource(inputSource);
	
	TransformerFactory transformerFactory = new ProfessionalTransformerFactory();
	Transformer transformer = transformerFactory.newTransformer(source);

	// Create XML SAX source
	Source xmlSource = new SAXSource(new InputSource(new File(xmlPath)
			.toURI().toString()));

	// Output stream result
	File outFile = new File(outPath);
	Result outputTarget = new StreamResult(outFile);

	// Run transformation
	System.out.println("Run transformation...");
	transformer.transform(xmlSource, outputTarget);
	
	System.out.println("Output file exists: " + outFile.exists());
	System.out.println("Can the output file be deleted? " + outFile.delete());
}

In my case, the result of the transformation is:

Run transformation...
Output file exists: true
Can the output file be deleted? false

Please register to edit this issue

Also available in: Atom PDF