javax.xml.transform.Source对象的文件名/路径

时间:2012-11-28 19:11:07

标签: java inputstream

我有一个扩展Source:InputSupplier<? extends Source> supplier的输入供应商,我想获取源的文件名(和路径)。

目前Source始终是StreamSource,因此我不知道这是否会带来或多或少的挑战。

1 个答案:

答案 0 :(得分:1)

StreamSource.getSystemId返回使用setSystemId设置的系统标识符,如果未调用setSystemId,则返回null。例子:

System.out.println(new StreamSource(new File("1.xml")).getSystemId());
System.out.println(new StreamSource(new FileReader("1.xml")).getSystemId());
System.out.println(new StreamSource(new FileReader("1.xml"), "d://workspace/x/1.xml").getSystemId());

打印

file:/D:/workspace1/x/1.xml
null
d://workspace/x/1.xml

所以这取决于StreamSource的创建方式。

相关问题