7/24/2014

java.util.Properties and character encoding

java.util.Properties class (see Java SE 7 Javadoc) by default assumes ISO 8859-1 character encoding in reading and writing. So when a properties file is in other character encoding, you will see strange characters and behaviors.

Properties class has no method or constructor that takes encoding or locale parameter. Fortunately, in Java SE 6, two new methods were added to allow for reading from java.io.Reader and writing to java.io.Writer:

public synchronized void load(Reader reader) throws IOException;

public void list(PrintWriter out)
So you can create Reader or Writer instances with appropriate encoding, and pass them to Properties load or list methods. For example,
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.Properties;

import org.junit.Test;

public class MyTest {

    @Test
    public void loadPropertiesTest() throws Exception {
        final File jndiPropertiesFile = new File(System.getProperty("user.home"), "tmp/jndi.properties");
        final FileInputStream fileInputStream = new FileInputStream(jndiPropertiesFile);

        // FileReader does not have any constructor that takes encoding, so use InputStreamReader instead
        final InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "UTF-8");

        final Properties jndiProperties = new Properties();
        jndiProperties.load(inputStreamReader);

        //now dump the properties to verify
        jndiProperties.list(System.out);
    }
}
Output from running loadPropertiesTest test:
-- listing properties --
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.provider.url=jnp://localhost:1099
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces

33 comments:

GeekOnJava said...

GeekOnJava

Anna said...

Great and Useful Article.

Online Java Training

Java Online Training India

Java Online Course

Java EE course

Java EE training

Best Recommended books for Spring framework

Java Interview Questions








Java Course in Chennai

Java Online Training India

fusionfinancilas said...

I have read your blog its very attractive and impressive.I would like to thank you for the sharing. We are also giving oracle financials Course Online Training,further information visit our site.

wingsio said...

Interesting article! Thank you for sharing them! I hope you will continue to have similar posts to share with everyone!

games draw said...

Great! Many thanks for sharing pianotiles2.com

Alice Taylor said...

great article, I was very impressed about it, wish you would have stayed next share


word-cookies-answers.com

Thu Lê said...

I was very impressed by this post, this site has always been pleasant news. Thank you very much for such an interesting post. Keep working, great job! In my free time, I like play game: douchebagworkout2.org. What about you?

Games 2 Girls said...

This is extremely helpful info!! Very good work. Everything is very interesting to learn and easy to understood. Thank you for giving information.
www.baixar-whatsapp.com.br

ngocanhng said...

I like your all post. You have done really good work. Thank you for the information you provide, it helped me a lot. I hope to have many more entries or so from you.
Very interesting blog.
minecraft2.com.br

Unknown said...


Thanks for sharing this good blog.This is very important and imformative blog for Java . very interesting and useful for students
Java Online Training Bangalore

bloxorz said...

Thank you for your analysis. It is new and different aspects I know before. Looking forward to reading more of your posts

happy wheels said...

I was already using the fork attribute. I added the memory attibutes and it worked like a champ!

DJ PRASATH said...

Thanks for your post. This is excellent information. The list of your blogs is very helpful for those who want to learn, It is amazing!!! You have been helping many application.
best selenium training in chennai | best selenium training institute in chennai

Krystal said...

Nice post. It is really interesting. Thanks for sharing the post!
Domain Registration Company in Singapore
Website design Singapore
Buy SSL certificate Singapore
Business email hosting service Singapore

Laxman S said...

I’m really impressed with your article, such great & usefull knowledge you mentioned here. Thank you for sharing such a good and useful information here in the blog
Kindly visit us @
SATHYA TECHNOSOFT (I) PVT LTD
Social Media Marketing Company | SMO Company India
Social Media Marketing Packages in India
PPC Campaign Price | Google Adwords Pricing in india
PPC Company in India | PPC Services India
Google Adwords company in India | Google Adwords Services in India
Best SEO Company in india | SEO Services in India
Bulk SMS Service India | Bulk SMS India

Sneha Sharma said...

Why Sri Yantra is one of the best Yantra for Money? Follow this link https://thebhakti.com/shri-yantra/ to know the Benefits of Shree Yantra, Shree Yantra Properties and learn more about Shree yantra ...

it's Sri yantra
it's Sri yantra mantra
it's Shree yantra online
it's where to place sri yantra
it's What is the Sri Yantra?
it's What is the meaning of a Yantra?

Sathya said...

Interesting information and attractive.This blog is really rocking... Yes, the post is very interesting and I really like it.I never seen articles like this. I meant it's so knowledgeable, informative, and good looking site. I appreciate your hard work. Good job.
Kindly visit us @
Sathya Online Shopping
Buy AC Online | AC Online Shopping | AC Price | Buy Air Conditioner Online
Inverter Split AC | Best Inverter AC | Split AC Price | Buy Split AC Online
Smart LED TV | Smart TV Price | LED TV Online | Buy LED TV Online
Laptop Online | Laptop Price | Buy Laptop Online | Best Laptop
Buy HD LED TV
Buy Ultra HD TV Online
Buy HD Ready LED TV
Buy Mobile Online

Clipping Path said...

Awesome post.Thanks for sharing

manisha said...

Do you mind if I quote a couple of your posts as long as I provide credit and sources back to your blog? My blog is in the same niche as yours, and my users would benefit from some of the information you provide here. Please let me know if this ok with you. Thank you.

apple iphone service center in chennai | apple ipad service center in chennai | iWatch service center chennai | apple iphone service center in chennai

sathya shri said...

I love the blog. Great post. It is very true, people must learn how to learn before they can learn. lol i know it sounds funny but its very true. . .
DevOps Training in Bangalore

DevOps Training in Bangalore

DevOps Training in Bangalore

DevOps Training in Marathahalli

DevOps Training in Pune

DevOps Online Training-gangboard

naveen said...

I have read a few of the articles on your website now, and I really like your style of blogging. I added it to my favourites blog site list and will be checking back soon.
DevOps Training in chennai

DevOps Training in chennai

DevOps Training in chennai

DevOps Training in Velachery

DevOps Training in Tambaram

DevOps Training in sholinganallur

DevOps Training in Annanagar

OLIVIA H said...

Awesome to read this blog.
apple iphone service center in chennai | apple ipad service center in chennai | apple iphone service center in chennai

Indonesian Training Courses said...

lampungservice.com
serviceiphonebandarlampung.blogspot.com
youtubelampung.blogspot.com
bimbellampung.blogspot.com
bateraitanam.blogspot.com

rohini said...

Thank you a lot for providing individuals with a very spectacular possibility to read critical reviews from this site.
Mobile service center in chennai | iphone service center in chennai | ipod battery replacement in chennai | ipad display replacement in chennai | 100% genuine mobile parts | Mobile phone display replacement in chennai | Mobile display replacement in chennai | Mobile service center in chennai | Mobile display replacement in chennai | Tablet battery replacement service in chennai | Latop service center in chennai | Mobile service center in chennai

Georgina Alexis said...

We are best and trusted bangladeshi online news portal website. Everyday we publish the national and international latest news. If you want to get regular newslatter from our newspaper, please go home page BANGLA NEWS and click the below subscribe button.

বাংলাদেশ :
Read Bangla Breaking বাংলাদেশ News on Parliament, Govt, Justice, Road Accident, Cricket, Sports, Education, Business, Agriculture, Population, Dhaka at todaybanglenews.com
রাজধানী :
রাজধানী ঢাকার সরকার/রাজনীতি, শিক্ষা, বিচার/আদালত, পুলিশ/অপরাধ, বিক্ষোভ/ধর্মঘট/প্রতিবাদ সমাবেশ, গোলাগুলি/আগুন/আহত, প্রেসক্লাব বিষয়ক খবর ও সংবাদ Dhaka news at todaybanglenews.com
আন্তর্জাতিক :
আন্তর্জাতিক,Read Bangla Breaking World News on USA, UK, India, Pakistan, Asia, China, Europe, Middle East, Latin America, Africa, Australia, America & UN at todaybanglenews.com
সম্পাদকীয় :
সম্পাদকীয় - সংবাদ গবেষণা, বিশ্লেষণ, অভিমত, মতামত, মন্তব্য বিশয়ক ফিচার। প্রথম আলো, বাংলাদেশের সর্বাধিক পঠিত অনলাইন বাংলা সংবাদপত্র/পত্রিকা at todaybanglenews.com
বিজ্ঞান ও প্রযুক্তি :
বিজ্ঞান ও প্রযুক্তি বিষয়ক খবর/সংবাদ - Bangla Technology News। কম্পিউটার সফটওয়্যার, ইন্টারনেট, মোবাইল, আইফোন/আইপ্যাড, উইন্ডোজ/মাইক্রোসফট, এনড্রয়েড/গুগল, নকিয়া, আপডেট/আপগ্রেড, গেমস, ফ্রিল্যান্সার বিষয়ে রিভিউ, গবেষণা, ও ফিচার at todaybanglenews.com
টিপস্ :
টিপস্, health tips bangla, health tips bangladesh, health tips bangla version, health tips bangla diabetes, health tips bangla language, health tips bangla pregnancy, health tips bangla women, health tips bangla health tips, healthy jibon, পুরুষের স্বাস্থ্য, health tips for human, health tips in bangla at todaybanglenews.com
বিনোদন খবর :
বিনোদন খবর ও সংবাদ - Bangla Movie and Entertainment News। ছবি, শুটিং, মঞ্চ, শিল্পী, নাচ বিষয়ক ফিচার। প্রথম আলো, বাংলাদেশের সর্বাধিক পঠিত অনলাইন বাংলা সংবাদপত্র/পত্রিকা at todaybanglenews.com
খেলাধুলা :
খেলার খবর/সংবাদ - খেলাধুলা, ক্রীড়া ও ক্রিকেট - Bangla Sports News। ফুটবল, ক্রিকেট, টেনিস, বিশ্বকাপ, শিরোপা, টি-টোয়েন্টি, বল, সেমি-ফাইনাল, বোলার বিষয়ক ফিচার at todaybanglenews.com


Georgina Alexis said...

We are the world best leading online newspaper portal. You all are the most welcome in our newspaper.If you want to get regular newslatter from our newspaper, please go home page sports news and click the below subscribe button.

World News :
View FOX world news today for international news and videos from Europe, Asia, Africa, the Middle East and the Americas. Visit world news tonight for up-to-the-minute news, breaking news, video, audio and feature stories.

Business News :
The latest FOX Business News: breaking personal finance, company, View the latest business news today about the world's top companies, and explore articles on global.

Sports News :
Latest sports news football from around the world with in-depth analysis, features, photos and videos covering football, tennis, motorsport, golf, rugby, sailing, skiing, horse racing and equestrian.

Entertainment News :
View entertainment news today and videos for the latest movie, music, TV and celebrity headlines on worldfoxnews.com

Technology News :
Get the latest FOX technology news science : breaking news and analysis on computing, the web, blogs, games, gadgets, social media, broadband and more.

Science News :
Get the latest FOX science news of today and Environment News: breaking news, analysis and debate on science and nature in the UK and around the world.

Health News :
Get the latest FOX health news recent: breaking health and medical news from the UK and around the world, with in-depth features on well-being and lifestyle.

Daily Life :
What You Need To Know About The daily life yoga? Get the latest lifestyle news with articles and videos on pets, parenting, fashion, beauty, food, travel, relationships and more on Fox news.

Georgina Alexis said...

We are the world best leading online newspaper portal. You all are the most welcome in our newspaper.If you want to get regular newslatter from our newspaper, please go home page health news and click the below subscribe button.

World News :
View CNN world news reuters today for international news and videos from Europe, Asia, Africa, the Middle East and the Americas. Visit CNN News for up-to-the-minute news, breaking news, video, audio and feature stories.

Business News :
The latest CNN Business News: breaking personal finance, company, View the latest business news nba about the world's top companies, and explore articles on global.

Sports News :
Latest sports news football from around the world with in-depth analysis, features, photos and videos covering football, tennis, motorsport, golf, rugby, sailing, skiing, horse racing and equestrian.

Entertainment News :
View entertainment news of today and videos for the latest movie, music, TV and celebrity headlines on usacnnnews.com
Technology News :
Get the latest CNN technology news science : breaking news and analysis on computing, the web, blogs, games, gadgets, social media, broadband and more.

Science News :
Get the latest CNN Science and Environment News: breaking news, analysis and debate on science news for today and nature in the UK and around the world.

Health News :
Get the latest CNN health news recent : breaking health and medical news from the UK and around the world, with in-depth features on well-being and lifestyle.

Daily Life :
What You Need To Know About The Good Life? Get the latest lifestyle news with articles and videos on pets, parenting, fashion, beauty, food, travel, relationships and more on CNN daily life news.

riamoni said...

Thanks for sharing.

[url=https://www.airlinesbooking.net/jetsetz-com-launches-new-travel-website-middle/]jetsetz[/url]

riamoni said...

Thanks for sharing.



Ophelia A. Hazelton said...

We are best and trusted bangladeshi online news portal website. Everyday we publish the national and international latest news. If you want to get regular newslatter from our newspaper, please go home page BANGLA NEWS and click the below subscribe button.

বাংলাদেশ :
Read Bangla Breaking বাংলাদেশ News on Parliament, Govt, Justice, Road Accident, Cricket, Sports, Education, Business, Agriculture, Population, Dhaka at todaybanglenews.com
রাজনীতি :
বাংলাদেশের রাজনীতির খবর/সংবাদ - Bangladesh Political News। সরকার, বিএনপি/আওয়ামী লীগ/জাতীয় পার্টি/জামায়াত, শেখ হাসিনা/খালেদা জিয়া/এরশাদ, উপজেলা, রাষ্ট্রপতি, ছাত্রলীগ/যুবলীগ/ছাত্রদল/যুবদল/ছাত্র সমাজ বিষয়ক ফিচার at todaybanglenews.com
আন্তর্জাতিক :
আন্তর্জাতিক,Read Bangla Breaking World News on USA, UK, India, Pakistan, Asia, China, Europe, Middle East, Latin America, Africa, Australia, America & UN at todaybanglenews.com
অর্থনীতি :
অর্থনীতি,Read Bangla Breaking World News on USA, UK, India, Pakistan, Asia, China, Europe, Middle East, Latin America, Africa, Australia, America & UN at todaybanglenews.com
ইসলাম ও জীবন :
ইসলাম ও জীবন, রমজান, ইজতেমা, মুসলিম বিশ্ব, মাসআলা-মাসায়েল, ইতিহাস ও ঐতিহ্য, সাক্ষাৎকার, bangladesh news, bangladesh newspaper, bangladesh news paper, bangladeshi newspaper, bangladeshi news paper at todaybanglenews.com
বিনোদন খবর :
বিনোদন খবর ও সংবাদ - Bangla Movie and Entertainment News। ছবি, শুটিং, মঞ্চ, শিল্পী, নাচ বিষয়ক ফিচার। প্রথম আলো, বাংলাদেশের সর্বাধিক পঠিত অনলাইন বাংলা সংবাদপত্র/পত্রিকা at todaybanglenews.com
খেলাধুলা :
খেলার খবর/সংবাদ - খেলাধুলা, ক্রীড়া ও ক্রিকেট - Bangla Sports News। ফুটবল, ক্রিকেট, টেনিস, বিশ্বকাপ, শিরোপা, টি-টোয়েন্টি, বল, সেমি-ফাইনাল, বোলার বিষয়ক ফিচার at todaybanglenews.com
লাইফ স্টাইল :

লাইফ স্টাইল, আমার পরিবার, ভ্রমণ, চাকরির খোঁজ, সমাধান, রান্না, রূপচর্চা, সংবাদ, টিপস, bangladesh news, bangladesh newspaper, bangladesh news paper, bangladeshi newspaper at todaybanglenews.com

Ophelia A. Hazelton said...

7 steps to health The Big Diabetes Lie review 2019

7 steps to health & the big diabetes lie is an excellent program, which is especially designed for the diabetes people who are all suffering in a long run in diabetes & 7 steps to health And The Big Diabetes Lie helps how to control your blood sugar level. 7 steps to health And The Big Diabetes Lie is a total natural home course which doesn’t require medication otherwise expensive equipment. Following properly tips and techniques included in 7 steps to health And The Big Diabetes Lie program will give you an important opportunity to be healthy pro the relax of your life. 7 steps to health And The Big Diabetes Lie program show some top secret on how to enhance the insulin level through natural methods, healthy meals & simple exercises.


oasisproperties17 said...

We are building a group of SAP PM coaches and members for their future assistance and help with subject. Our training will be centered around aiding placements also. We have a different HR group experts who will deal with all your meeting needs. Our SAP PM Training Course Fees is extremely moderate contrasted with others. We are the main SAP PM training establishment who can share video surveys of every one of our understudies. We referenced the course timings and begin date too underneath.

For More Info:- SAP PM Course in Gurgaon

straightener said...

شركة مكافحة الصراصير فى دبى
شركة مكافحة حشرات في دبى
شركة تنظيف سجاد في دبي
شركة تنظيف بعجمان
شركة مكافحة حشرات فى عجمان