Sometimes, We want to read properties file which contains non-english characters.

For example, properties file contains UTF-8 encoding characters. Default encoding for properties file reading is ISO-8859-1

Spring framework loads the properties file in default encoding

In this tutorial, How to read and write a properties file content with configured encoding in Java

How to configure encoding for Spring boot to read

In this example, you will learn how to Read key and its values from an properties file spring boot application.

Let’s have properties file which contains non-english characters.


There are number of ways properties file read in spring core and boot applications

One way is using PropertiesFactoryBean

  • create a Bean object of returning PropertiesFactoryBean using @Bean annotation
  • Inside create a object
  • set encoding using setFileEncoding method
  • configure to read properties file from ClassPathResource setLocation method
public PropertiesFactoryBean propertiesfilemapping() {
    PropertiesFactoryBean factoryBean = new PropertiesFactoryBean();
    factoryBean.setLocation(new ClassPathResource(""));
    return factoryBean;

Next, you can access properties file mapped to member variables using @Value annotation with below syntax

private String name;

Another way, using @PropertySource annotation with value contains name of file and encoding to UTF-8

@PropertySource(value = “classpath:/”, encoding=“UTF-8”)

Third way, Reading directly properties key with encoding

  • Configure PropertySource mapping
@PropertySource(value = "classpath:/")

read individual properties with getProperty method with encoding

propertiesObject.getProperty("name").getBytes("ISO-8859-1"), "UTF-8")

How to read from property file containing utf 8 character in java

Reading properties file is an easy way to do in java.

You can apply encoding for file input stream as seen in the below example

import java.nio.charset.Charset;
import java.util.Properties;
import java.util.Set;

public class PropertiesReader {
    public static void main(String[] args) {
        Properties properties = new Properties();
        File file = new File("B:\\");

        try {
            FileInputStream inputStream = new FileInputStream(file);

            properties.load(new InputStreamReader(inputStream, Charset.forName("UTF-8")));
        } catch (FileNotFoundException fie) {
        } catch (IOException e) {
        Set<String> keys = properties.stringPropertyNames();
        for (String key : keys) {
            System.out.println(key + " - " + properties.getProperty(key));


You learned how to configure properties file to read UTF-8 character encoding in spring framework and boot as well as Java.