As a test, I copied and pasted your code in a CarTest4.java file, and it compiles and runs fine; no errors. Your last error (java.lang.NoClassDefFoundError) is probably due to a bad classpath. Make sure your classpath includes the directory which contains CarTest4.class
Sorry, I didn't understand your question at first. Perhaps this will work:
File curDir = new File( original );
String parentPath = curDir.getParent();
File parentDir = new File( parentPath );
String parentDirName = parentDir.getName();
Seems like more code than necessary, though.
You could also do something like this:
File curDir = new File( original );
String parentDir = curDir.getName();
The File.getName() method returns the last directory/file name in a path.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.