Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #33395 > unrolled thread
| Started by | Prashant Savadi <prsh.jkd@gmail.com> |
|---|---|
| First post | 2015-12-26 21:48 -0800 |
| Last post | 2015-12-27 09:39 -0800 |
| Articles | 3 — 3 participants |
Back to article view | Back to comp.lang.java.programmer
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
| From | Prashant Savadi <prsh.jkd@gmail.com> |
|---|---|
| Date | 2015-12-26 21:48 -0800 |
| Subject | Can anyone help me how to read UTF-16 file in java 7. |
| Message-ID | <dad762d3-7cf8-4c8b-bc2d-17b05065fd35@googlegroups.com> |
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.
[toc] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2015-12-27 09:21 -0500 |
| Message-ID | <n5os5f$7d3$1@speranza.aioe.org> |
| In reply to | #33395 |
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
[toc] | [prev] | [next] | [standalone]
| From | Lew <lewbloch@gmail.com> |
|---|---|
| Date | 2015-12-27 09:39 -0800 |
| Message-ID | <486de56d-cde2-4097-bcbf-71e3679acf1f@googlegroups.com> |
| In reply to | #33396 |
@Prashant, you'll want to familiarize yourself with the API docs on Oracle.com, because you could have looked that up there in five minutes.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web