hfhbd
03/12/2026, 1:54 PMMichael Paus
03/12/2026, 2:08 PMfun kotlinx.io.files.Path.toNioPath(): java.nio.file.Path = java.nio.file.Path.of(this.toString())hfhbd
03/12/2026, 2:11 PMMichael Paus
03/12/2026, 2:13 PMjw
03/12/2026, 2:16 PMhfhbd
03/12/2026, 2:17 PMjw
03/12/2026, 2:17 PMhfhbd
03/12/2026, 2:20 PMMichael Paus
03/12/2026, 3:24 PMhfhbd
03/12/2026, 3:25 PMtoString() method for my use-case, but like Jake said, it might not work in all cases.Michael Paus
03/12/2026, 3:26 PMjw
03/12/2026, 3:26 PMjw
03/12/2026, 3:27 PMFilipp Zhinkin
03/13/2026, 2:29 PM<http://kotlinx.io|kotlinx.io>.files.Path in particular, as it handles things badly, but on Unix systems file names (and path segments) are not obliged to be valid string and are just sequences of bytes (the only restriction - the should not contain / and \0 ).
Thus, if there's a file with a name that is not a valid utf8 sequence, you can still get a Path pointing to it using java.nio.file.Files.list (Java's Unix Paths holds byte array with a file name internally, not a string), but the conversion via .toString() will no longer work for such a Path .Michael Paus
03/13/2026, 4:26 PM| File System | Internal Representation | Key Characteristic |
|-------------|-------------------------|---------------------------------------------|
| NTFS | UTF-16LE | Stores names as 16-bit Unicode code units. |
| ext4 / XFS | Opaque Byte String | Encoding-agnostic; usually treated as UTF-8.|
| APFS | UTF-8 | Modern Apple standard; normalization-aware. |
| HFS+ | UTF-16 | Legacy Apple; forces NFD normalization. |
| FAT32 | OEM / UTF-16 | Uses UTF-16 specifically for Long Filenames.|jw
03/13/2026, 4:29 PMjw
03/13/2026, 4:30 PMjw
03/13/2026, 4:30 PMFilipp Zhinkin
03/13/2026, 6:12 PMMeaning these FSs know nothing about UTF-8, and it's up to an application how to interpret the byte string.Copy code| ext4 / XFS | Opaque Byte String | Encoding-agnostic; usually treated as UTF-8.|