java写入xml路径问题

丰富的分地方的 2009-11-05 04:10:50
我用public static boolean doc2XmlFile(Document document,String filename){
boolean flag = true;
try
{
/** 将document中的内容写入文件中 */
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer();
/** 编码 */
//transformer.setOutputProperty(OutputKeys.ENCODING, "GB2312");
DOMSource source = new DOMSource(document);
StreamResult result = new StreamResult(new File(filename));
transformer.transform(source, result);
}catch(Exception ex)
{
flag = false;
ex.printStackTrace();
}
return flag;
}
方法把修改后的xml写进去,不知道怎么取相对路径。。
...全文
79 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
我有个xml文件放在包的路径里,是config.xx.config.xml我修改后怎么用相对路径写进去额?
swandragon 2009-11-05
  • 打赏
  • 举报
回复
//当前类的classpath的URI目录
System.out.println(FilePath.class.getResource("/"));

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧