Sunday, 15 September 2013

netbeans - reading text file with utf-8 encoding using java -



netbeans - reading text file with utf-8 encoding using java -

i have problem in reading text file utf-8 encoding i'm using java netbeans 7.2.1 platform

i configured java project handle utf-8 javaproject==>right click==>properties==>source==>utf-8

but still unknown character output: ����� �������� ���� �

the code:

file filedirs = new file("c:\\file.txt"); bufferedreader in = new bufferedreader( new inputstreamreader(new fileinputstream(filedirs), "utf-8")); string str; while ((str = in.readline()) != null) { system.out.println(str); }

any other ideas?

thanks

use

import java.io.bufferedreader; import java.io.file; import java.io.fileinputstream; import java.io.ioexception; import java.io.inputstreamreader; import java.io.unsupportedencodingexception; public class test { public static void main(string[] args){ seek { file filedir = new file("path_to_file"); bufferedreader in = new bufferedreader( new inputstreamreader( new fileinputstream(filedir), "utf8")); string str; while ((str = in.readline()) != null) { system.out.println(str); } in.close(); } grab (unsupportedencodingexception e) { system.out.println(e.getmessage()); } grab (ioexception e) { system.out.println(e.getmessage()); } grab (exception e) { system.out.println(e.getmessage()); } } }

you need set utf-8 in quotes

java netbeans file-io encoding

No comments:

Post a Comment