Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #33396

Re: Can anyone help me how to read UTF-16 file in java 7.

Path csiph.com!news.fcku.it!aioe.org!.POSTED!not-for-mail
From Arne Vajhøj <arne@vajhoej.dk>
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 <n5os5f$7d3$1@speranza.aioe.org> (permalink)
References <dad762d3-7cf8-4c8b-bc2d-17b05065fd35@googlegroups.com>
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

Show key headers only | View raw


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<String> lines = Files.readAllLines(fnm, StandardCharSets.UTF_16);

But there are plenty of alternatives.

Arne

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Can anyone help me how to read UTF-16 file in java 7. Prashant Savadi <prsh.jkd@gmail.com> - 2015-12-26 21:48 -0800
  Re: Can anyone help me how to read UTF-16 file in java 7. Arne Vajhøj <arne@vajhoej.dk> - 2015-12-27 09:21 -0500
    Re: Can anyone help me how to read UTF-16 file in java 7. Lew <lewbloch@gmail.com> - 2015-12-27 09:39 -0800

csiph-web