Can't use latin characters correctly when creating new files from within Java. Filenames get weird characters instead of the correct ones -


currently saving int[] hashmap in file name of key int[]. exact key must reachable program. hence can't switch name of files english chars. though use iso_8859_1 charset filenames files messed in file tree. english letters correct not special ones.

        /**         * save array file         */         public void savestatus(){             try {                 for(string currentkey : hmap.keyset()) {                     byte[] currentkeybytearray = currentkey.getbytes();                     string bytesstring = new string(currentkeybytearray, standardcharsets.iso_8859_1);                     string filelocation = "/var/tmp/" + bytesstring + ".dat";                     fileoutputstream savefile = new fileoutputstream(filelocation);                     objectoutputstream out = new objectoutputstream(savefile);                     out.writeobject(hmap.get(currentkey));                     out.close();                     savefile.close();                     system.out.println("saved file @ " + filelocation);                 }             } catch (ioexception e) {                 e.printstacktrace();             }         } 

could have how linux encoding characters or more java code?

edit

i think problem lies os. because when looking @ text files cat example problem same. vim able decode letters correctly. in case have perhaps change language settings terminal?

you have change charset in getbytes function well.

currentkey.getbytes(standardcharsets.iso_8859_1); 

also, why using standardcharsets.iso_8859_1? accept wider range of characters, use standardcharsets.utf_8.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -