DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Read UTF-8 File In Java

06.07.2005
| 92567 views |
  • submit to reddit
        
BufferedReader in = new BufferedReader(new FileReader("file"));
while( (s = in.readLine()) != null) {
		
	String UTF8Str = new String(s.getBytes(),"UTF-8"));
}
    

Comments

Snippets Manager replied on Mon, 2012/05/07 - 2:12pm

Much better! Thanks a lot llucifer. Until this, I've never work with UTF-8 encoded files in Java. Edu

Snippets Manager replied on Mon, 2012/05/07 - 2:12pm

A better solution might be: Reader in = new InputStreamReader(new FileInputStream("file"), "UTF-8"));