Path: csiph.com!news.fcku.it!aioe.org!.POSTED!not-for-mail From: =?UTF-8?Q?Arne_Vajh=c3=b8j?= Newsgroups: comp.lang.java.programmer Subject: Re: Can anyone help me how to read UTF-16 file in java 7. Date: Sun, 27 Dec 2015 09:21:34 -0500 Organization: Aioe.org NNTP Server Lines: 26 Message-ID: References: NNTP-Posting-Host: ANasIS7Js9OyLQwgloeBLQ.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.5.0 X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com comp.lang.java.programmer:33396 On 12/27/2015 12:48 AM, Prashant Savadi wrote: > I am trying read UTF-16 encoded file in JDK 7, can anyone help me out. I can able to read in Python by: > > fread = open(r'sample.dat', 'rb').read() > mytext = fread.decode('utf-16') > print mytext > I tried so many ways in java 7 but not succeeded. Thanks in advance. Traditional: BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(fnm), "UTF-16")); String line; while((line = br.readLine()) != null) { // process line } More close to youe Python code: List lines = Files.readAllLines(fnm, StandardCharSets.UTF_16); But there are plenty of alternatives. Arne