This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Application path problem  RSS feed

 
Steve Wood
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

I'm having a problem with file paths.

Basically, if you launch the application in Windows by double-clicking an associated file, the application seems to take the path as that of the file, not the actual application. If I load the application normally, it takes the correct path.

To illustrate:

/application/myexe.exe
/application/myimage.jpg

double clicking myexe.exe loads the image fine because I use:

File file = new File("");
file.getAbsolutePath() + File.separator + "myimage.jpg";

but if I load the application by double-clicking a file:

/desktop/file.txt

file.getAbsolutePath() returns /desktop, not /application. So it can't find the image file then because it thinks it should be at /desktop.

Is there any way to get around this?

Any help is greatly appreciated.

Cheers,

Steve
 
Serghei Jelauc
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.
Try somethig like this:


I had such problem before, and I solved it as I mentioned above (but I do not remember exactly).

Hope this will help.
[ December 01, 2004: Message edited by: Serghei Jelauc ]
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!