• Post Reply Bookmark Topic Watch Topic
  • New Topic

file reading trouble  RSS feed

 
Kyle Berry
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This doesnt work for some reason... its not reading it right from my file i think... any suggestions?

 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, two major things. One is that if the password file doesn't exist, you simply do nothing. A better thing to do would be to report the problem, preferably including the absolute path of the missing file -- that would give you a clue if the program was loooking in the wrong place -- i.e.,



Second, and this is at least as important if not moreso, if there's a problem with the file I/O, Java will report it by throwing an IOException. YOu're catching that IOException and... utterly ignoring it -- preferring, apparently, to come here and ask total strangers what might be going wrong, rather than letting Java tell you what is wrong. Always log exceptions if you're not going to report them to the user (here, the latter is a better choice.)

Third, don't use System.out.println() in a GUI app -- that's silly. Use JOptionPane.showErrorDialog(). It's easy and it looks a heck of a lot better!

Now go forth, my son, and never write an empty catch block again. Seriously. Or I'll hunt you down, I swear...
 
Kyle Berry
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aight thanks ill try this and see if it works!

Originally posted by Ernest Friedman-Hill:

Now go forth, my son, and never write an empty catch block again. Seriously. Or I'll hunt you down, I swear...


x.x hunt me all you want ull never find me!
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any bugs in your program could probably say the same, Kyle.
 
memati bas
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your file is directory, so can you guess what happened ??
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!