• Post Reply Bookmark Topic Watch Topic
  • New Topic

InputStreamReader looking for file location  RSS feed

 
Derek Kennard
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The file (let's call it file.txt) is on the C:\ of my machine. I'm using and looking for the user to enter the location of the file in the console. How do I (the user) enter the path to the file in the console. I have tried everything... "C:\file.txt", \\C:\\file.txt\\, and a million other combinations. Nothing seems to work. How does the console expect the file path to be written so it knows how to pick up the file?
 
Piet Souris
Master Rancher
Posts: 2044
75
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Derek,

typing in the path:

c:\file.txt

without quotes should do the trick. I just tried it. See:

and this is input and output:

Where is the file?:
D:\JavaProgs\ProjectEuler\src\Hulpbestanden\Oplossing van Euler063.ods
ingelezen regel D:\JavaProgs\ProjectEuler\src\Hulpbestanden\Oplossing van Euler063.ods
bestand bestaat WEL
BUILD SUCCESSFUL (total time: 4 seconds)

Are you sure your file does exist?

Greetz,
Piet
 
Paul Clapham
Sheriff
Posts: 22844
43
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The console doesn't expect anything. Nor does it know how to pick up files. All it does in that code is to read what you type and make it available for more of your code to process that.

The "more code" I'm referring to is code after what you posted which would read a line from that BufferedReader. That line would contain the line you typed.

And by the way what you should type is what you would normally use for a file path (i.e. the first of the 1,000,002 combinations you described in your post). No need to use Java escape conventions because you aren't typing a Java string literal to be interpreted by the Java compiler here.
 
Ron McLeod
Bartender
Posts: 1603
232
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It would be c:\file.txt. You can try something like this to prove that out:
After that, work on getting the file name from the console.

Sorry - realized that that example I gave will not work - the \ would need to escaped, so it would be "c:\\file.txt". Ignore my advise.
 
Piet Souris
Master Rancher
Posts: 2044
75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ron McLeod wrote:

This will give an "Illegal Escape character" error. In this case you must use "c:\\file.txt";

Greetz,
Piet
 
Ron McLeod
Bartender
Posts: 1603
232
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Piet - I thought about that just after I posted.
 
Piet Souris
Master Rancher
Posts: 2044
75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Ron,

quess what my first result was when I typed my initial little code given earlier?

Greetz,
Piet
 
Derek Kennard
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, I figured it out. It was figured out by several peoples posting, so thank you all. The console needed the java-like path C:\\file.txt... it was the double \\ that threw me off

Thank you everyone
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!