Is it possible to load in a txt file into java, but from a folder in say the c: drive - as opposed to placing the text file in the java project itself?

Thanks in advance for any help

Recommended Answers

All 5 Replies

Just include the FULL path in the File object:

File f = new File("C:/Program Files/Java/file.txt");

thanks, that does it.

Just include the FULL path in the File object:

File f = new File("C:/Program Files/Java/file.txt");

So what really happens when I entered that line of code??
Does that code automatically do something when performed by the system?,
or another line of code will have follow it for something to happen??

what really happens when I entered that line of code

Please show the "line of code" you are referring to.

for something to happen

What is the "something" that is to happen?
Each executable statement does something or causes something to happen.

It just creates a File object that refers to the file with that path & name, but it doesn't actually do anything with it (not even check if the file exists!). You can then call methods on that File object to test if it exists, open it and read it etc

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.