0
我有一个扩展的输入提供者来源:InputSupplier<? extends Source> supplier
我想获取源的文件名(和路径)。javax.xml.transform.Source对象的文件名/路径
目前Source始终是一个StreamSource,所以我不知道这是否使它更具挑战性。
我有一个扩展的输入提供者来源:InputSupplier<? extends Source> supplier
我想获取源的文件名(和路径)。javax.xml.transform.Source对象的文件名/路径
目前Source始终是一个StreamSource,所以我不知道这是否使它更具挑战性。
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的是如何创建的。
请显示更多代码 – home
@home我可以显示哪些其他代码? –
源代码不一定是指文件或路径......它可能只是来自远程位置的流。所以这一切都取决于你的代码(你创建源代码的方式)。 – home