我试图在属性文件中添加十六进制值,这个值正在被存储,但是我可以看到一个"\"正在被追加,我不想这样,
test.properties
#
#Fri Jun 07 21:18:49 GMT+05:30 2013
test=fe\:feJava文件
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文件中的输入和属性文件中的输出相同?
发布于 2013-06-07 16:20:33
考虑以已知的方式编码十六进制值,并用C和Java对它们进行解码。
一种方法是在十六进制值前面加上"0x“,并使用所有大写的数字。如果你使用这一技术,你将需要某种方式来发出信号结束一个十六进制的数字。我建议使用空格字符(‘')或行尾。
使用此技术,您的属性将如下所示:
test=0xFEFE
字符串"Blam07kapow“( 07是一个十六进制数字)如下所示:
Blam0x07 kapow
发布于 2013-06-07 16:05:48
Properties类存储:使用前面的\,以确保在使用load方法时它将再次加载适当的值。如果您希望稍后能够将这个属性文件加载回java中,那么恐怕属性文件中的转义字符会被困住。请参阅java.util.Properties文档
https://stackoverflow.com/questions/16988264
复制相似问题