I have a problem or a question regarding Java and or Eclipse. I have a programm that does the following:
- open up a UI where the user can search for a folder
- if the folder is picked the absolut path is getting passed to the main
- there are few folders in that chosen path
- there are functions that read from the data and create a new excel with the read data
- The path that I am getting is correct!
Gernerally the programm works... But it only works if:
The chosen Path from the User is a folder that is inside the project folder where I run the programm from.
OR
The Names of the files that are getting read are specified inside the project folder. What I mean with that is: if the file test.vcc is inside the package then I could open it from the desktop if there is a file that is also named test.vcc
So it seems like Java or Eclipse cant open up paths that are not inside the project or named in the project - is that true?
Running the programm gives me NullPointerExceptions for every File that is not especially named or inside the project.
Sincerly Faded
Update
Okay so I have noticed something that I am doing wrong definetly!
I was replacing the whole FILEPATH that the User choses with ".\" which obviouslly means that it will not care about the filepath and replace it with .\ instead of really taking the path.
String filePathS = filePath.replace(FILEPATH, ".\\");
When I am using this it works because it can find the files in the project Folder. So after seeing this I just took the real Path that the user choosed.
Its basically this:
String filePathSX = filePath.replace("/", "\\");
or this
String filePathSX = filePath.replace("\\", "/");
which either gives me a Path like this: C:\Users\me\dev\foldername\part\test.txt or like this C:/Users/me/dev/foldername/part/test.txt
I can check that in the destination the file test.txt does indeed exist and the path is correct. Still when it tries to do something with that file it gives me a NullPointerExeption.
IF I would leave the replace function for the whole path with .\, then it would take the test.txt file that is inside the package and it would run without any problems.
So I think that I am somehow accsessing the file in the wrong way. How should the path look like on windows if the user chooses something? c/user/... or c\user...
Because both ways do not work for me.