Android IDE (AIDE) Support Forum

Unable to obtain absolute path of current directory

I’m trying to obtain the absolute file path of the directory in which my code is running. The two lines in the picture where I initialize a Path and then print it should do it, but it’s not working for some reason.

Expected output: “Current absolute directory: /storage/emulated/0/AppProjects/DnDCharacterSheet/src/”

Actual output: “Current absolute directory: /”

I’ve tried a few other ways to get the absolute path too, and all of them just return “/” instead of the actual path. How can I get the absolute directory so that I can read in my text file without having to hardcode its file path?

The documentation for the Path interface says that accessing a FileSystem using an empty path is the equivalent of accessing the default FileSystem. The default FileSystem isnt were your app is placed. Looking at the FileSystem documentation it says calling getDefault returns the working user directory which is the current user directory. So try calling System.getProperty(“user.dir”) if im reading the documentation right it should give you the same thing /

That was one of the other solutions I tried. System.getProperty(“user.dir”) just returns “/”, same as the code in the picture

This works for me, should be easy to modify to work with a Scanner but tbh your better of not using Scanner anyways because its a lot slower and IIRC has a 1KB buffer, i dont know anything about DND except what ive seen/heard on tv but it seems pretty complicated so im guessing thats not a small file your working with.

I’m only looking for a way to obtain the absolute path of a file in AIDE. Not looking for any other comments on my code, thanks.

No your looking to make this code magically do what you want it to and its never going to, so il leave you with a hint

/storage/emulated/0/AppProjects/DnDCharacterSheet/src/” is NOT the directory in which your code is running, them 2 lines of code you wrote do NOT and should NOT return that

That is not a solution its not even close to it :confused: the reason it returns / is because thats exactly what it should be returning like i said i expected it to, before you told me you already tried it. I know documentation can be unclear sometimes but this time it was crystal clear. You can not do what your trying to do the way your trying to do it

Why do not you work in your application namespace?

You may require user input of working directory.