java reads file system file names differently on osx and linux

phomlish

I have a java program that is almost working perfectly. I'm developing on a mac and pushing to linux for production. When the mac searches the file system and inserts new file names to the database it works great. However, when I push to the linux box and do the search/insert it finds files with some characters as different IE: Béla Fleck. They look identical to me in the database and on the mac AND linux file systems. In fact, the mac and linux boxes have NFS mounts to a 3rd system (linux) where the files reside.

I've dumped the bytes and can see how linux and mac are seeing the string from the file system: Béla Fleck.

linux:

utf8bytes[0] = 0x42
utf8bytes[1] = 0x65
utf8bytes[2] = 0xcc
utf8bytes[3] = 0x81
utf8bytes[4] = 0x6c
utf8bytes[5] = 0x61
utf8bytes[6] = 0x20
utf8bytes[7] = 0x46
utf8bytes[8] = 0x6c
utf8bytes[9] = 0x65
utf8bytes[10] = 0x63
utf8bytes[11] = 0x6b

linux says LANG=en_US.UTF-8

mac:

utf8Bytes[0] = 0x42
utf8Bytes[1] = 0xc3
utf8Bytes[2] = 0xa9
utf8Bytes[3] = 0x6c
utf8Bytes[4] = 0x61
utf8Bytes[5] = 0x20
utf8Bytes[6] = 0x46
utf8Bytes[7] = 0x6c
utf8Bytes[8] = 0x65
utf8Bytes[9] = 0x63
utf8Bytes[10] = 0x6b

mac says LANG=en_US.UTF-8

tried this, still no joy.

java -Dfile.encoding=UTF-8

I'm using java nio file to get the directory:

java.nio.file.Path path = Paths.get("test");

then walking the path with

Files.walkFileTree(path, new SimpleFileVisitor<Path>() {

and then, since this is a subdir in the test path:

 file.getParent().getName(1).toString()

Anyone have any ideas on what is glitching here and how I can fix this?

Thanks.

VGR

Some searching revealed that OS X always decomposes file names:

This suggests to me that you may have accidentally switched the outputs: the first byte array is decomposed, so I’m guessing it was taken from a Mac, whereas the second one is from Linux.

In any event, if you want them to be identical for all systems, you can do the decomposition yourself:

String name = file.getParent().getName(1).toString();
name = Normalizer.normalize(name, Normalizer.Form.NFD);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Which file system to use in between OSX and Linux

From Dev

Windows operating system unable to open file names that works on linux

From Dev

Build OSX .pkg file on linux

From Dev

Remove question mark "?" from file names OSX

From Dev

Reads a Txt file on a webserver on Raspbian (Linux)

From Dev

Linux file system architecture

From Dev

Distributed file system for linux

From Java

Linux - Replacing spaces in the file names

From Linux

linux rename file names recursively

From Dev

How to write a shell script that reads all the file names in the directory and finds a particular string in file names?

From Dev

Java reads file directory and creates a link to a pdf

From Dev

Node bin file not being recognized on linux or osx

From Java

Save PDF file using Java Printable on Linux system

From Dev

How to use the default File Chooser for the operating system in Java (in Linux and Windows)

From Dev

Accessing linux local file system from java web application

From Dev

JAVA file sending system

From Dev

File System that supports duplicate directory names

From Dev

System.Object[] - when file names are same

From Dev

Make a specific program see the file-system differently on Windows

From Dev

Linux file system for a big file server

From Dev

Unix and Linux without a file system?

From Dev

Linux Booting with USB File System

From Dev

What is a pseudo file system in Linux?

From Dev

Linux File System for an External HDD

From Dev

file system uid and gid in linux

From Dev

Write Linux System Information to File

From Dev

Nerdtree ^G before folder and file names OSX terminal vim

From Dev

Method read in linux reads characters that doesn´t exist in the file

From Dev

Node.js File System - Saving unique file names

Related Related

  1. 1

    Which file system to use in between OSX and Linux

  2. 2

    Windows operating system unable to open file names that works on linux

  3. 3

    Build OSX .pkg file on linux

  4. 4

    Remove question mark "?" from file names OSX

  5. 5

    Reads a Txt file on a webserver on Raspbian (Linux)

  6. 6

    Linux file system architecture

  7. 7

    Distributed file system for linux

  8. 8

    Linux - Replacing spaces in the file names

  9. 9

    linux rename file names recursively

  10. 10

    How to write a shell script that reads all the file names in the directory and finds a particular string in file names?

  11. 11

    Java reads file directory and creates a link to a pdf

  12. 12

    Node bin file not being recognized on linux or osx

  13. 13

    Save PDF file using Java Printable on Linux system

  14. 14

    How to use the default File Chooser for the operating system in Java (in Linux and Windows)

  15. 15

    Accessing linux local file system from java web application

  16. 16

    JAVA file sending system

  17. 17

    File System that supports duplicate directory names

  18. 18

    System.Object[] - when file names are same

  19. 19

    Make a specific program see the file-system differently on Windows

  20. 20

    Linux file system for a big file server

  21. 21

    Unix and Linux without a file system?

  22. 22

    Linux Booting with USB File System

  23. 23

    What is a pseudo file system in Linux?

  24. 24

    Linux File System for an External HDD

  25. 25

    file system uid and gid in linux

  26. 26

    Write Linux System Information to File

  27. 27

    Nerdtree ^G before folder and file names OSX terminal vim

  28. 28

    Method read in linux reads characters that doesn´t exist in the file

  29. 29

    Node.js File System - Saving unique file names

HotTag

Archive