Way to convert paths to OS Specific format? [message #58349] |
Mon, 29 September 2003 21:04 ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: mharp.seapine.com
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?
For example, on Windows it would give me back "c:\fred\class1.java" and
Linux would give me back "c:/fred/class1.java".
Thanks for any help you can provide,
harpstein
|
|
|
Re: Way to convert paths to OS Specific format? [message #58371 is a reply to message #58349] |
Tue, 30 September 2003 09:09 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: bob.news.gmx.net
"Harpstein" <mharp@seapine.com> schrieb im Newsbeitrag
news:bla6i9$nlq$1@eclipse.org...
> 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
|
|
|
Re: Way to convert paths to OS Specific format? [message #58393 is a reply to message #58371] |
Tue, 30 September 2003 13:19 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: mharp.seapine.com
Actually, I found the Path class which has a ctor that takes a raw string.
Then I just call toOSString and that seems to work for me.
Thanks,
harpstein
"Robert Klemme" <bob.news@gmx.net> wrote in message
news:blbh5m$s70$1@eclipse.org...
>
> "Harpstein" <mharp@seapine.com> schrieb im Newsbeitrag
> news:bla6i9$nlq$1@eclipse.org...
> > 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
>
|
|
|
|
Re: Way to convert paths to OS Specific format? [message #595457 is a reply to message #58371] |
Tue, 30 September 2003 13:19 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: mharp.seapine.com
Actually, I found the Path class which has a ctor that takes a raw string.
Then I just call toOSString and that seems to work for me.
Thanks,
harpstein
"Robert Klemme" <bob.news@gmx.net> wrote in message
news:blbh5m$s70$1@eclipse.org...
>
> "Harpstein" <mharp@seapine.com> schrieb im Newsbeitrag
> news:bla6i9$nlq$1@eclipse.org...
> > 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
>
|
|
|
Powered by
FUDForum. Page generated in 0.03217 seconds