Search code examples
eclipsefileeclipse-plugineclipse-rcpcreation

File creation in Eclipse on linux depends on how it Eclipse is started


I am making my own Eclipse plugin but ran into unexpected behavior.

When running Eclipse from Command Line:

$ cd /home/user/downloads;/home/user/eclipse/eclipse

And i call functionality which creates a new file outside the workspace:

new java.io.File("home/user/folder/file")

it will return a new file with the path:

/home/user/downloads/home/user/folder/file

So it adds the path of the change directory command when i started eclipse.

If this is intentionally how should i create my file?


Solution

  • There is no such class as java.net.File presumably you mean java.io.File

    The path home/user/folder/file is a relative path - that is it is relative to the current directory whatever that may be. So if your current directory is /home/user/downloads the full file path will be /home/user/downloads/home/user/folder/file

    If you don't want this to happen you must specify an absolute path - on Unix, Linux and Macs that is a path starting with / so

    new java.io.File("/home/user/folder/file");
    

    (note the leading /) will give you a file with that exact path.