#Easiest fix, unsure why FileIO is not properly working.

1 messages · Page 1 of 1 (latest)

lethal fulcrum
#

Trying to get my project to read in my inFile. I compile the program to work, and the file cannot be found for some reason. My .txt is outside the src file and inside the project build, basically the same level as my src file.

rapid badgeBOT
#

This post has been reserved for your question.

Hey @lethal fulcrum! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

last light
#

Show me the code

void pollen
#

For files within your jar, you’re gonna wanna use Class#getResource/Class#getResourceAsStream rather than using file io

lethal fulcrum
#

Here's my program

glacial ridge
lethal fulcrum
glacial ridge
#

try /inFile.txt

lethal fulcrum
glacial ridge
#

does the absolute path match for any of the two versions match the expected path ?

glacial ridge
# lethal fulcrum

to phrase it differently is the absolute path of the file matching the absolute path of the file when checking in the explorer ?

void pollen
#

Also double check that you've actually set up that file to be included when your project is built.
You can quickly check this by just unzipping the compiled jar and seeing if it's even in there.

light mural
#

That looks like it would be a .war, not a .jar.

#

A nonstandalone web app that needs to be run in a container

#

The container isn't going to use the project's "src" dir as working directory

#

Nor is it going to inspect it as a source for resource files

#

If that file is supposed to be part of that application, then it should be a resource of it. As this is not a Maven layout, the simpler to achieve that is to put that file alongside the .java files

#

Then, it cannot be read with filesystem IO, because in the end it's supposed to be part of a .war archive, not a file on the filesystem. So it will need to be read with getResourceAsStream()

rapid badgeBOT
#

💤 Post marked as dormant

This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.