1

I have a project on my eclipse, one of its methods are reading list of files from a folder. when I run it from eclipse or from an exported jar, its fine and works great.

But I have another project on my netbeans for the GUI of this app where I include the exported jar (which works fine) but when I run or export this project from netbeans, it just can't read non-english filenames, it's converting the filenames to something like this

???????? ???? ??? .mp3 

I tried to add -J-Dfile.encoding=UTF-8 to the netbeans.conf and I also tried to select the encoding in the netbeans project properties but no luck.

here is some code:

public SFile(String path, FileFilter filter) {
    File f = null;
    f = new File(path);
    directory = f.isDirectory();
    if (directory) {
        children = new ArrayList<SFile>();
        File[] ki = f.listFiles(filter); // here i see the ???? ????.mp3
        ArrayList<File> kids = new ArrayList<File>();
        Collections.addAll(kids, ki);
        Collections.sort(kids, comparator);
        for (File k : kids) {
            if (k.isDirectory() && k.listFiles(filter).length == 0) {
                continue;
            }
            children.add(new SFile(k.getAbsolutePath(), filter));
        }
    } else {
        // some more code...
    }
}

the filter code:

new FileFilter() { 
     public boolean accept(final File pathname) { 
     try {
         return pathname.getCanonicalPath().endsWith(".mp3") || pathname.isDirectory();
     } catch (final IOException e) {
     e.printStackTrace(); 
     } 
     return false; 
     }
};

my project dependencies:

/Users/dima/Dev/RSLib/asm-3.1.jar
/Users/dima/Dev/RSLib/grizzly-framework-2.2.16.jar
/Users/dima/Dev/RSLib/grizzly-http-2.2.16.jar
/Users/dima/Dev/RSLib/grizzly-http-server-2.2.16.jar
/Users/dima/Dev/RSLib/grizzly-rcm-2.2.16.jar
/Users/dima/Dev/RSLib/gson-2.2.2.jar
/Users/dima/Dev/RSLib/javax.servlet-api-3.1-b05.jar
/Users/dima/Dev/RSLib/jersey-bundle-1.16.jar
/Users/dima/Dev/RSLib/jersey-core-1.16.jar
/Users/dima/Dev/RSLib/jersey-grizzly2-1.16.jar
/Users/dima/Dev/RSLib/jersey-server-1.16.jar
/Users/dima/Dev/RSLib/jsr311-api-1.1.1.jar
/Users/dima/Dev/RSLib/log4j-1.2.17.jar
/Users/dima/Dev/RSLib/jid3lib-0.5.4.jar
/Users/dima/Dev/RSLib/cling-distribution-2.0-alpha2/cling-mediarenderer-2.0-alpha2-standalone.jar
/Users/dima/Dev/RSLib/cling-distribution-2.0-alpha2/cling-workbench-2.0-alpha2-standalone.jar
/Users/dima/Dev/RSLib/cling-distribution-2.0-alpha2/core/seamless-http-1.0-alpha2.jar
/Users/dima/Dev/RSLib/cling-distribution-2.0-alpha2/core/seamless-util-1.0-alpha2.jar
/Users/dima/Dev/RSLib/cling-distribution-2.0-alpha2/core/seamless-xml-1.0-alpha2.jar
/Users/dima/Dev/RSLib/cling-distribution-2.0-alpha2/support/cling-support-2.0-alpha2.jar
/Users/dima/Dev/RSLib/cling-distribution-2.0-alpha2/core/cling-core-2.0-alpha2.jar
/Users/dima/Dev/RSLib/MpegAudioSPI1.9.5/mp3spi1.9.5.jar
/Users/dima/Dev/RSLib/MpegAudioSPI1.9.5/lib/jl1.0.1.jar
/Users/dima/Dev/RSLib/MpegAudioSPI1.9.5/lib/tritonus_share.jar
Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Dima
  • 8,586
  • 4
  • 28
  • 57
  • Are you reading a list of filenames then displaying them in a GUI? If so, lets see the display code. – Perception May 03 '13 at 20:47
  • no, i am not displaying them, im indexing all the files to hashmap with incrementing ID, when i stop for debugging, i see the non english filenames as ???????.mp3 and the java cant read them – Dima May 03 '13 at 21:25
  • "i see the non english filenames as ???????.mp3" Where do you see them? In the IDE somewhere? On a watch? In the output pane? – Danack May 04 '13 at 02:11
  • it would also be useful to see the actual code that reads the filename – Mr_and_Mrs_D May 04 '13 at 02:33
  • i see it when i debug, there is a String path (a good one,english) and i create a File f, and do a listFiles(), in there, when i am watching the returned array, the non-english ones are "??????.mp3", i updated my question, added the code. – Dima May 04 '13 at 10:34
  • You should go to them and fill a bug report... – Mr_and_Mrs_D May 05 '13 at 14:52

1 Answers1

1

If you are on java 7 listFiles is reported broken on mac OS X - see here and links there. If updating does not fix it you should consider moving to nio - or see here.
I'd ike to see the filter you pass in listFiles(filter);

Community
  • 1
  • 1
Mr_and_Mrs_D
  • 32,208
  • 39
  • 178
  • 361
  • strange thing, when im using the nio like you said in a main method, it works(on the eclipse currently) but when im using it inside my code, its also returns "??? ????????.mp3", any ideas? – Dima May 05 '13 at 06:53
  • @DimaGoltsman : did you try with latest java 1.7 ? Also please be sure to post _all the code that modifies the pathname_ I suspect you (or your dependencies) are calling a String constructor with the default encoding – Mr_and_Mrs_D May 05 '13 at 13:28
  • installed JDKu21 , still the same – Dima May 05 '13 at 14:00
  • i just noticed that in the JFileChooser itself, its also unknown symbols instead of the real filename... – Dima May 05 '13 at 14:11
  • @DimaGoltsman : Please remove `javax.servlet-api-3.1-b05.jar` - it leads to all kind of crazy behavior - may be the cause. Probably you should go ahead and delete other jars in your classpath - please read : http://stackoverflow.com/a/1993522/281545. You did it for not setting a server up in netbeans ? Go ahead and set the server up ! – Mr_and_Mrs_D May 05 '13 at 14:14
  • i removed it, and also removed the asm, still the same... i think the problem is much deeper because its also showing wrong filenames in jfilechooser – Dima May 05 '13 at 14:27
  • OK!!!! my search is over, the problem was netbeans, when i changed to java 1.6 it was still compiling with 1.7, i removed the 1.6 platform from the properties in netbeans and added it again, and now it works! thank you for your time! so we can understand that java 1.7 still not fixed – Dima May 05 '13 at 14:45
  • @DimaGoltsman : Ah great - if you are to display those filenames have a look [here](http://shamsmi.blogspot.gr/2008/03/internationalize-swings-jfilechooser-in.html) - and [here](http://stackoverflow.com/questions/7477610/java-jfilechooser-getting-international-filenames). Update your question with your updated dependencies. Always clean build your project to be sure. Glad to help and _thanks for the bounty_ :)) – Mr_and_Mrs_D May 05 '13 at 14:48