Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Input files???

 
Rose Evans
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You guys I have a question. I'm trying to write this program, and so far, it's doing mainly what I want it to do, except for one part where I ask the user to input their file name. When they input their file name, (assuming they enter the correct file name), it's supposed to bring up on the screen what's on that file. And so far it DOES do that, BUT, I accidently entered a wrong file name and it brings up everything that is in PetRecords.txt. And I can enter 'any' file name and the info comes up.
I know it's something simple to fix this.

And I'm thinking it needs to be fixed around this area:

BufferedReader inputStream = new BufferedReader (new FileReader("PetRecords.txt"));

Take a peek at my code and see what you think.




I swear my code always looks so goofy when I paste it on here. Shoot.

Anyway, I'd appreciate any help or tips you could give me. And remember talk in 'small' talk because I surely don't know the 'big' stuff yet like you guys do.

HUGS to all!
 
Rose Evans
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh my code doesn't look so bad after all now that I look at it. Ha.
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Um...If you're always specifying that it reads PetRecord.txt, then that's what its going to do. You are specifying a constant value instead of a variable.

Try this line:



Of course, that's not going to work on the line where it's currently declared. You'll have to move it after the declaration of fileName.
 
Rose Evans
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh hey, thank you, thank you, thank you!!! I had actually wrote that line of code and removed the PetRecords.txt and put fileName there, but I didn't move the actual code to a different place. Yeahhhhhhhhhhhhhhhhhhhhh, thank you for giving me a tip....
THANK YOU, THANK YOU, THANK YOU!!! :jumpingjoy
 
Rose Evans
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic