【问题标题】:file cannot be deleted error showing file is open in the java su binary close the file and try again文件无法删除错误显示文件已在 java su 二进制文件中打开关闭文件并重试
【发布时间】:2012-09-04 08:49:59
【问题描述】:

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

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

【问题讨论】:

  • 您在代码中的哪个位置尝试删除哪个文件?
  • public static void main(String[] args, String xmlpath) ???
  • 我使用 html 添加了一个小 ui,用于浏览 xml 文件并将文件路径发送到 servlet 并从那里发送到上述类,转换后我将页面重定向到另一个 html,显示转换成功跨度>
  • 我找到了答案,感谢您花费宝贵的时间来调查我的问题@nfechner

标签: java xml xls


【解决方案1】:
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
{

}
}
}

【讨论】:

    猜你喜欢
    • 2012-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多