简体   繁体   English

Java-从System.in加载正确的XML

[英]Java - Load a correct XML from System.in

I am trying to load an XML document from System.in in order to be able to pipe my program. 我试图从System.in加载XML文档,以便能够传输我的程序。 But the XML doesn't seem to load correctly since I get a NullPointerExeption where my program is looking for root element. 但是XML似乎无法正确加载,因为我在程序寻找根元素的地方得到了一个NullPointerExeption I am trying to use this solution . 我正在尝试使用此解决方案

Here is my code to load from System.in (never prints out "ok") : 这是我从System.in加载的代码(从不打印出“ ok”):

org.jdom2.Document jdomDoc
public LoadFile(String fileLocation) {
    if (fileLocation.compareTo("System.in") == 0) {
        Scanner sc = new Scanner(System.in);
        log.info(sc.toString()); // debug purpose
        while (sc.hasNextLine()) {
            log.info("ok"); // debug purpose
            jdomDoc.addContent(new Element(sc.nextLine()+ "\n"));
        }
     }

And I give fileLocation " System.in " if no -i (input) parameter has been found. 如果没有找到-i(输入)参数,我给fileLocation“ System.in ”。 I run it from cmd with : myXml.xml|java -jar myProgramm.jar 我使用以下myXml.xml|java -jar myProgramm.jar从cmd运行它: myXml.xml|java -jar myProgramm.jar

好的,愚蠢的错误,我的命令中有简单的错字:忘记了键入 myXml.xml|java -jar myProgramm.jar

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM