简体   繁体   中英

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. But the XML doesn't seem to load correctly since I get a NullPointerExeption where my program is looking for root element. I am trying to use this solution .

Here is my code to load from System.in (never prints out "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 run it from cmd with : myXml.xml|java -jar myProgramm.jar

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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