Cants seem to get java to recognize a text file.

I cant seem to get java to recognize a text file
No description
No description
44 Replies
JavaBot
JavaBot3mo ago
This post has been reserved for your question.
Hey @stapps! Please use /close or the Close Post button above when your problem is solved. 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.
dan1st
dan1st3mo ago
What do you mean with recognize a text file? Why should it?
stapps
stappsOP3mo ago
So I can print out how many words are in the text filw
dan1st
dan1st3mo ago
What happens when running your program?
stapps
stappsOP3mo ago
It's says it doesn't see it, I'll take a screenshot after I get back
stapps
stappsOP3mo ago
No description
dan1st
dan1st3mo ago
It seems you are running the program in C:\Users\Admin so it expects the file to be there
stapps
stappsOP3mo ago
the file is in the same folder as the program
stapps
stappsOP3mo ago
No description
dan1st
dan1st3mo ago
yeah but that's not where you run the program
stapps
stappsOP3mo ago
? is where its ran and where the program is different?
dan1st
dan1st3mo ago
yes
stapps
stappsOP3mo ago
oh
dan1st
dan1st3mo ago
For example assume you have a directory a with a directory b in it and your program is located in b If you are in directory a and run ./a/b (so you run the program from directory a), it still runs in directory a so if it tries to access test.txt, it looks for it in a
stapps
stappsOP3mo ago
lemmie try putting them both in a different folder to see if anything changes so would i have to put the text file in a different directory or make the directory different?
dan1st
dan1st3mo ago
Here, I think you are running the program in C:\Users\Admin so the file would need to be there yeah, you can also run the program from another directory
stapps
stappsOP3mo ago
like this?
No description
dan1st
dan1st3mo ago
the test.txt would need to be in C:\Users\Admin or just run the program in the directory where the test.txt is
stapps
stappsOP3mo ago
is this not C:\User\admin?
dan1st
dan1st3mo ago
I don't know you just wrote C:\Users\fnum in the top bar
stapps
stappsOP3mo ago
i did not, i moved it to the directory, it still wont work :'D
stapps
stappsOP3mo ago
actually, the error is different now
No description
dan1st
dan1st3mo ago
So how are you running the application and where is the test.txt file?
stapps
stappsOP3mo ago
No description
stapps
stappsOP3mo ago
both the file and program files are in the same folder
dan1st
dan1st3mo ago
and how do you run that?
stapps
stappsOP3mo ago
i press the run button
dan1st
dan1st3mo ago
It doesn't matter whether they are in the same folder if you run it from another folder
stapps
stappsOP3mo ago
how would i run it from another folder?
dan1st
dan1st3mo ago
then VSC is configured to rujn it in some folder Is there a launch.json?
stapps
stappsOP3mo ago
idk
dan1st
dan1st3mo ago
Can you configure how you are running the Java application in VSC? idk VSC much
stapps
stappsOP3mo ago
i think so, im moving the entire vcs to the desktop to see if that works
dan1st
dan1st3mo ago
When i run a Java program in VSC/Theia, I have a settings icon
No description
dan1st
dan1st3mo ago
when I click it, it opens a launch.json
dan1st
dan1st3mo ago
this has an entry like this
No description
dan1st
dan1st3mo ago
and I can add a cwd entry which specifies where the program is run
No description
stapps
stappsOP3mo ago
is this the same?
No description
dan1st
dan1st3mo ago
if you specify the full path there, you need to specify the path to the file, not the path to the directory so "C:\\Users\\fnum\\test.txt" or similar
stapps
stappsOP3mo ago
oh different error message this time
stapps
stappsOP3mo ago
No description
stapps
stappsOP3mo ago
IT WORKS
No description
JavaBot
JavaBot3mo ago
💤 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. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
stapps
stappsOP3mo ago
.Close .close
Want results from more Discord servers?
Add your server