After renaming files with Java some not accessible on linux system or via Java After renaming files with Java some not accessible on linux system or via Java linux linux

After renaming files with Java some not accessible on linux system or via Java


Try to declare -Dfile.encoding=UTF-8 in you java start command.


First, two points :

1) The fact that you are getting errors with ls shows that the problem is an issue between the filenames and the filesystem, not Java per se. You would get the same issue whatever language your program was written in - or indeed, if you tried to copy or rename a file directly on the command line.

2) The problem is not with the quote character, as is shown by the fact that the quote character appears in files that were named correctly - eg :

-rw-rw-rw- 1 root root 52822606 Feb 21  2017 11 - Carmen Suites for orchestra Nos. 1 & 2 (assembled by Ernest Guirard)- Nocturne (Micaela's Aria, Act III).WAV

So, the problem is with the unicode character é .

This character is this one : https://www.compart.com/en/unicode/U+00E9 , so it consists of a null byte followed by E9.

The trouble is that POSIX filesystems like xfs do not allow null bytes in filenames (see What are all the illegal characters in the XFS filesystem? )

Upshot is, you cannot have filenames with THAT character in THAT filesystem.

So, you have to change either the filename, or the filesystem.

For example, this page lists filesystems, indicating those that allow unicode in their filenames :

https://en.wikipedia.org/wiki/Filename#Comparison_of_filename_limitations

(as an aside, in that list is Apple's HFS+, but interesting to note that that has been replaced by the Apple File System APFS that does NOT allow unicode in filenames - https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/APFS_Guide/FAQ/FAQ.html )

The other alternative to change your Java program to modify the filename to replace é with e :

    String safeFilename = filename.replaceAll("é", "e");

or if you prefer :

    String safeFilename = filename.replaceAll( "\u00e9", "e" );


That is a nice challenging puzzle you got there as this is hard to debug

I tried to reproduce with java.nio.Files with Java 11 on Debian 10 with XFS and bash (as ls builtin) but could not reproduce the issue with files named é.

Please try to get to a simpler reproduction scenario and more details otherwise I just have to guess that this may have to do with:

The problem is also that this seems to be hard to debug as simple tools like strace do not show enough information on the bytes of the filenames getdents syscall to see what is going on at the lower level API's, see: for what I mean

Maybe it is time for a different strategy? Try to only write the full title of the songs to a playlist file? There will always be special chars that will in some setting cause problems, even spaces with scripts if you are uncareful, directory seperators (slash or backslash) etc. (See: this related question )