Solved

Get Japanese folder name path

Posted on 2006-07-02
4
390 Views
Last Modified: 2010-10-05
Hi everyone

I am using Eclipse to create a Java project named Test under this workspace:
C:\09_あい うえStep1\Program\Suzuki

My project has only one class Test.java as below:

package vn.com.abc;

public class Test
{

  public static void main(String[] args)
  {
     System.out.println(getFullPath());
  }
      
  public static String getBaseDir()
  {
    String path;
    path = Test.class.getResource(Test.class.getSimpleName() + ".class").getPath();            
    return path;
  }
}

I ran this project and expected to get:
 C:\09_あい うえStep1\Program\Suzuki\Test\classes\vn\com\abc\Test.class

However, what I'd got was:
 /C:/09_%e3%81%82%e3%81%84%e3%80%80%e3%81%86%e3%81%88Step1/Program/Suzuki/Test/classes/vn/com/abc/Test.class

This mean that my program doesn't work if I put my project in a path contain Japanese name.

Could you please help me to solve this problem

Many thanks

Brimountain


0
Comment
Question by:brimountain
  • 2
4 Comments
 
LVL 92

Expert Comment

by:objects
ID: 17028798
getResource() returns a URL, so getPath() is going to return the URL path and not the file path
0
 

Author Comment

by:brimountain
ID: 17028847
Hi objects

I just want to get the full path the file Test.class in runtime.

This statement, path = Test.class.getResource(Test.class.getSimpleName() + ".class").getPath();        

works fine in English name folder, but doens't work in Japanese name folder.  

Is there anyway to get around this problem?  

Bri
0
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 17028853
you need to convert the url encoded string, try:

path = URLDecoder.decode(path, "UTF8");
0
 
LVL 26

Expert Comment

by:ksivananth
ID: 17028861
you may have to convert the path string to unicode bytes using appropriatte charset and then display.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

943 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now