# Reading a UTF-16-LE file

**URL:** <https://discourse.julialang.org/t/reading-a-utf-16-le-file/11687>\
**Category:** General Usage\
**Tags:** question\
**Created:** [June 15, 2018, 6:52am UTC](https://discourse.julialang.org/t/reading-a-utf-16-le-file/11687 "2018-06-15T06:52:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![freeboson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freeboson/32/2198_2.png) [@freeboson](https://discourse.julialang.org/u/freeboson)\
**Post date:** [June 15, 2018, 6:52am UTC](https://discourse.julialang.org/t/reading-a-utf-16-le-file/11687/1 "2018-06-15T06:52:51Z")

</div>

I would like to read from a `utf-16-le`-encoded file. In this case, it’s a tsv. In python, I can read it as:

```python
import pandas as pd

with open('file.tsv', encoding='utf-16-le') as f:
    df = pd.read_table(f)

```

In Julia, I _think_ I should `open`, do `readbytes!` into a `Vector{UInt8}`, convert/reshape to `Vector{UInt16}`, then call `LegacyStrings.utf16`, just to get the string data. Is there a simpler way?

---

<div class="post-metadata">

**Author:** ![Daneel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/daneel/32/175_2.png) [@Daneel](https://discourse.julialang.org/u/Daneel)\
**Post date:** [June 15, 2018, 7:04am UTC](https://discourse.julialang.org/t/reading-a-utf-16-le-file/11687/2 "2018-06-15T07:04:44Z")

</div>

Have you tried StringEncodings?

```julia
using StringEncodings
fid = open(path,enc"UTF-16LE","r")
...

```

> **[GitHub - JuliaStrings/StringEncodings.jl: String encoding conversion in Julia...](https://github.com/JuliaStrings/StringEncodings.jl)**
>
> String encoding conversion in Julia using iconv. Contribute to JuliaStrings/StringEncodings.jl development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![freeboson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freeboson/32/2198_2.png) [@freeboson](https://discourse.julialang.org/u/freeboson)\
**Post date:** [June 15, 2018, 10:17am UTC](https://discourse.julialang.org/t/reading-a-utf-16-le-file/11687/3 "2018-06-15T10:17:51Z")

</div>

No, and this looks perfect. Thanks!

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [June 15, 2018, 1:11pm UTC](https://discourse.julialang.org/t/reading-a-utf-16-le-file/11687/4 "2018-06-15T13:11:03Z")

</div>

> [@freeboson](#):
>
> In Julia, I _think_ I should `open` , do `readbytes!` into a `Vector{UInt8}` , convert/reshape to `Vector{UInt16}` , then call `LegacyStrings.utf16` , just to get the string data. Is there a simpler way?

Without using external packages, you can use the built-in `transcode` function:

```julia
f = IOBuffer(transcode(UInt8, ltoh.(reinterpret(UInt16, read("file.tsv"))))
...read data from `f`...

```

(On little-endian machines you could omit the `ltoh` call.) Use `transcode(String, ...)` to get a `String` instead, but an `IOBuffer` may be more convenient if you want to use it with other I/O routines.

---

<div class="post-metadata">

**Author:** ![olegshtch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/olegshtch/32/219677_2.png) [@olegshtch](https://discourse.julialang.org/u/olegshtch)\
**Post date:** [December 6, 2025, 5:09pm UTC](https://discourse.julialang.org/t/reading-a-utf-16-le-file/11687/5 "2025-12-06T17:09:45Z")

</div>

Is StringEncodings still actual in 2025th?

I get error:

ERROR: Conversion from UTF16-LE to UTF-8 not supported by iconv implementation, check that specified encodings are correct

Julia: v1.12.2  
StringEncodings: v0.3.7

---

<div class="post-metadata">

**Author:** ![tp2750](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tp2750/32/207806_2.png) [@tp2750](https://discourse.julialang.org/u/tp2750)\
**Post date:** [December 6, 2025, 5:58pm UTC](https://discourse.julialang.org/t/reading-a-utf-16-le-file/11687/6 "2025-12-06T17:58:28Z")

</div>

It is called “UTF-16LE”, not “UTF16-LE”. 😉
