文件无法删除错误显示文件在java su二进制文件中打开关闭文件并重试

时间:2012-09-04 08:50:00

标签: java xml xls

我想删除该文件或复制由该程序创建的文件,它不允许我需要解决方案

package xml2html;

import java.io.*;
import javax.xml.transform.*;
import javax.xml.transform.stream.*;

public class Xml2HtmlConverter {

public static void main(String[] args, String xmlpath) {
    pathmethod(xmlpath);
}

public static void pathmethod(String xmlpath) {
      try {
        /* converting the file using xls */
        TransformerFactory tFactory = TransformerFactory.newInstance();

        Source xslDoc = new StreamSource("D:/xmlautomation/stylesheet.xsl");
        Source xmlDoc = new StreamSource(xmlpath);

        String outputFileName = "D:/xmlautomation/output.html";
        OutputStream htmlFile = new FileOutputStream(outputFileName);

        Transformer transformer = tFactory.newTransformer(xslDoc);
        transformer.transform(xmlDoc, new StreamResult(htmlFile));

      } catch(Exception e) {
         e.printStackTrace();
      }
    }
 }

1 个答案:

答案 0 :(得分:0)

package xml2html;

import java.io.*;
import javax.xml.transform.*;
import javax.xml.transform.stream.*;

public class Xml2HtmlConverter {

public static void main(String[] args, String xmlpath)
{
    pathmethod(xmlpath);
}

public static void pathmethod(String xmlpath) 
{
try
    {
        TransformerFactory tFactory = TransformerFactory.newInstance();

        Source xslDoc = new StreamSource("D:/xmlautomation/stylesheet.xsl");
        Source xmlDoc = new StreamSource(xmlpath);

        String outputFileName = "D:/xmlautomation/output.html";
        OutputStream htmlFile = new FileOutputStream(outputFileName);

        Transformer transformer = tFactory.newTransformer(xslDoc);
        transformer.transform(xmlDoc, new StreamResult(htmlFile));
        htmlFile.close();     
    }

catch(Exception e)
{
    e.printStackTrace();
}

finally
{

}
}
}