Space character without “” in properties file keys


I reed properties file:

InputStream input = new FileInputStream("data.ini");
Reader reader = new InputStreamReader(input, Charset.forName("UTF-8"));
Properties prop = new Properties();

My properties file Key contains space and I need to put character to read it correctly. Is it possible somehow not place character in properties file and read it in correct way?

Properties file content:

aaa bbb=0


It is possible to load properties from an XML file also… makes for neater code.


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "">
    <comment>Sample Properties file in XML</comment>
    <entry key="PropertyWithoutSpaces">Property value</entry>
    <entry key="Property With Spaces">Property value</entry>

import java.util.Properties;

public class PropertyTest {

    public static void main(String[] args) throws IOException {
        Properties properties = new Properties();
        properties.loadFromXML( new FileInputStream("properties.xml") );

        System.out.println( properties.getProperty("Property With Spaces") );
        System.out.println( properties.getProperty("PropertyWithoutSpaces") );


Source: stackoverflow