[英]Different behavior between netbeans and shell windows
I wrote a small program in Java using Netbeans 8.02 (JDK8; java version 1.8.0_45). 我使用Netbeans 8.02(JDK8; Java版本1.8.0_45)用Java编写了一个小程序。 It reads an XML file (in UTF-8 encoding), finds and replaces the character "&", parses the file and signs it.
它读取一个XML文件(采用UTF-8编码),查找并替换字符“&”,解析该文件并对其进行签名。
Executing this program from Netbeans it's all right. 从Netbeans执行此程序就可以了。 Executing the same program from windows XP shell i meet errors about the encoding of the file to be signed.
从Windows XP Shell执行同一程序时,遇到有关要签名文件的编码的错误。 Executing the same program from windows 7 shell every thing is fine.
从Windows 7 Shell执行相同的程序,一切都很好。
somebody knows what cause this different behavior? 有人知道导致这种不同行为的原因是什么?
to minimize the distance between this different behaviors, and thus avoiding errors of BOM and charset, I solved in this way: 为了最小化这种不同行为之间的距离,从而避免BOM和字符集的错误,我以这种方式解决了:
f = new File(PatInputFile);
String sif = readfile(PatInputFile,StandardCharsets.UTF_8);
byte[] contentInBytes = sif.replaceAll("&", "&").getBytes("UTF-8");
FileOutputStream fop =new FileOutputStream(f);
fop.write(contentInBytes);
fop.flush();
fop.close();
where 哪里
private static String readfile(String path, Charset encoding) throws IOException
{
byte[] encoded = Files.readAllBytes(Paths.get(path));
return new String(encoded, encoding);
}
and so on parsing and signing the file "f" . 等等,对文件“ f”进行解析和签名。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.