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

Re: reading external files into java 80 80

Just include the FULL path in the File object:

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

Re: reading external files into java 80 80

thanks, that does it.

Re: reading external files into java 80 80

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??

Re: reading external files into java 80 80

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.

Re: reading external files into java 80 80

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 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.