gpt4 book ai didi

java - 在Java属性文件中存储十六进制值,不带 "\"

转载 作者:太空宇宙 更新时间:2023-11-04 07:35:12 25 4
gpt4 key购买 nike

我正在尝试在属性文件中添加十六进制值,该值正在被存储,但我可以看到附加了一个“\”,这是我不想要的,

测试.属性

#
#Fri Jun 07 21:18:49 GMT+05:30 2013
test=fe\:fe

Java 文件

public class PropertySave {
private static File s_file;
private static Properties s_properties = new Properties();
public static void main(String[] args) {
loadProperties();
s_properties.setProperty("test", "fe:fe");
saveProperties();
}
private static void saveProperties() {
FileOutputStream fout = null;
try {
fout = new FileOutputStream(s_file);
s_properties.store(fout, "");
} catch (IOException ioe) {
ioe.printStackTrace();
System.exit(1);
} finally {
if (fout != null) {
try {
fout.close();
} catch (final IOException ioe2) {
ioe2.printStackTrace();
System.exit(1);
}
}
}
}
private static void loadProperties() {
s_file = new File("test.properties");
if ((!s_file.exists()) || (!s_file.isFile())) {
System.exit(1);
}
FileInputStream fin = null;
try {
fin = new FileInputStream(s_file);
s_properties.load(fin);
} catch (IOException ioe) {
ioe.printStackTrace();
System.exit(1);
} finally {
if (fin != null) {
try {
fin.close();
} catch (final IOException ioe2) {
ioe2.printStackTrace();
System.exit(1);
}
}
}
}
}

在java文件中s_properties.setProperty("test", "fe:fe");属性文件中的输出不同(test.properties)fe:fe我想忽略这个,因为这个属性文件是用"C"语言输入到其他系统的,因此我的东西无法工作,

我应该怎么做才能确保java文件中的输入和属性文件中的输出相同

最佳答案

考虑以已知方式对十六进制值进行编码,并在 C 和 Java 中对其进行解码。

一种技术是在十六进制值前面加上“0x”并使用全部大写的数字。如果您使用此技术,您将需要某种方式来表示十六进制数的结束。我建议使用空格字符 (' ') 或行尾。

使用这种技术,您的属性将如下所示:

测试=0xFEFE

字符串“Blam07kapow”,其中 07 是十六进制数字,如下所示:

Blam0x07 kapow

关于java - 在Java属性文件中存储十六进制值,不带 "\",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16988264/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com