Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将XMl文件转换为字符串_Java_Xml_String - Fatal编程技术网

Java 将XMl文件转换为字符串

Java 将XMl文件转换为字符串,java,xml,string,Java,Xml,String,我正在使用java将xml文件转换为字符串 我的xml是 <GTSRequest command="version"> <Authorization account="account" user="user" password="password"/> </GTSRequest> 但是,当我将XMl转换为字符串时,我的输出将改变,这是我不想要的。 输出为 <?xml version="1.0" encoding="UTF-8" standalone="

我正在使用java将xml文件转换为字符串 我的xml是

<GTSRequest command="version">
<Authorization account="account" user="user" password="password"/>
</GTSRequest>
但是,当我将XMl转换为字符串时,我的输出将改变,这是我不想要的。 输出为

<?xml version="1.0" encoding="UTF-8" standalone="no"?><GTSRequest command="version">
<Authorization account="account" password="password" user="user"/>
</GTSRequest>

密码和用户更改按字母顺序排列

我该如何解决这个问题呢?

您正在将XML转换为文档,并在序列化之后

如果只希望文件像文本文件一样读取文件:

BufferedReader br = new BufferedReader(new FileReader(fileName));
try {
    StringBuilder sb = new StringBuilder();
    String line = br.readLine();

    while (line != null) {
        sb.append(line);
        sb.append(System.lineSeparator());
        line = br.readLine();
    }
    String everything = sb.toString();
} finally {
    br.close();
}
BufferedReader br = new BufferedReader(new FileReader(fileName));
try {
    StringBuilder sb = new StringBuilder();
    String line = br.readLine();

    while (line != null) {
        sb.append(line);
        sb.append(System.lineSeparator());
        line = br.readLine();
    }
    String everything = sb.toString();
} finally {
    br.close();
}