Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/380.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法删除文件错误,显示文件已在java su二进制文件中打开。请关闭该文件,然后重试_Java_Xml_Xls - Fatal编程技术网

无法删除文件错误,显示文件已在java su二进制文件中打开。请关闭该文件,然后重试

无法删除文件错误,显示文件已在java su二进制文件中打开。请关闭该文件,然后重试,java,xml,xls,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)

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

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();
      }
    }
 }

您在代码中的哪个位置尝试删除哪个文件?
publicstaticvoidmain(String[]args,String xmlpath)
???我添加了一个使用html的小ui,用于浏览xml文件,并将文件路径发送到servlet,然后从servlet发送到上面的类。转换后,我将页面重定向到另一个html,显示转换成功。我找到了答案,感谢您花宝贵的时间查看我的问题@nfechner
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
{

}
}
}