file - Java - shorten the path of a directory -


i shorten path of directory.

i know directory path must start, example (the path starts 1):

instead of c:\temp\top\1\file.txt, want 1\file.txt.

note: careful \ , /....

you can traverse path file root, check if dir dir want:

file basedir = new file(basepath); file candidate = new file(fullpath); string subpath = candidate.getname(); candidate = candidate.getparent();  while (candidate != null && !candidate.equals(basedir)) {     candidate = candidate.getparent();     subpath = candidate.getname() + file.separatorchar + subpath; }  // if candidate == null file on directory, have use path // if candidate != null, subpath has want 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -