Im facing a problem with umlauts in groovy/java on a ubuntu server.
This groovy code return for exists() false for files with umlauts:
def f1 = new File('/var/lib/jenkins/test/')
def files = [:]
f1.listFiles().each {
files.put(it.name, it.getAbsoluteFile().exists())
}
println files
println 'file.encoding:' + System.getProperty('file.encoding')
Results in:
Verderblichkeit.docx:true
Gefa��hrlichkeit.docx:false
file.encoding:"iso-8859-1"
So it return false for a file it found itself with listFile(). That is wrong.
ls -al in the drirectory:
drwxr-xr-x 2 jenkins jenkins 4096 Jan 5 18:17 .
drwxr-xr-x 66 jenkins jenkins 12288 Jan 5 18:16 ..
-rw-r--r-- 1 jenkins jenkins 98035 Jan 5 18:16 Gefährlichkeit.docx
-rw-r--r-- 1 jenkins jenkins 277515 Jan 5 18:17 Verderblichkeit.docx
In linux I can copy or mv or rename the files and see the umlauts.
Environment:
- Version of Java: Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Note: The original problem is getting the file path from a database. The file can be found and served throug nginx but in the java app (grails with groovy files) I get a false result for File.exists()
What can I do?
I tried setting UTF-8 as file.encoding by setting this in the application environment or by -D param on start. I searched the web but didn't find a solution.