[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
|
[news.eclipse.technology] Re: Way to convert paths to OS Specific format?
|
"Harpstein" <mharp@xxxxxxxxxxx> schrieb im Newsbeitrag
news:bla6i9$nlq$1@xxxxxxxxxxxxxx
> Hey all,
>
> I've got the string "c:\fred\class1.java"
>
> Is there some kind of static method or any other way to ask Eclipse to
give
> me back the path for the current platform that I'm on?
I think that is not possible for a fundamental reason: When given a string
without further information the source system is unknown and thus the
convention for path separators is unknown.
A proper solution could use File.getName() and File.getParent() on the
source side to split up the complete path into a list of path components
(Strings) and then use File.File(File, String) to reconstruct it on the
target side.
> For example, on Windows it would give me back "c:\fred\class1.java" and
> Linux would give me back "c:/fred/class1.java".
This could easily be achieved by aPathString.replaceAll( "[/\\\\]", "\\" +
File.separatorChar ) but be warned that this is not a portable solution at
all.
Regards
robert