Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem Using PrintWriter class !

 
Muzafar Ali
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys,
i am using File class with PrintWriter class,
when i declare File class object it works wel but when i am creating the PrintWriter class object it show me error message (UnHandled Exception Type FileNotFoundException) what should i do here is the program please correct it and give me working version.

Thanks,
Muzafar
 
Muzafar Ali
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,

I solved it myself.
One question when i Declared all the methods simple Without using Throws Exception it shows me error but when i used Throws Exception along with method then it works but why ? can any one explain it for me?



Thanks,
Muzafar
 
Fred Hamilton
Ranch Hand
Posts: 684
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In addition to having the method throw the exception as you have done here, you should also learn about the try/catch method of handling exceptions.

Anyways, in this case it's all about how the program is supposed to react if the filename you specify in the program doesn't actually exist. You have to tell the program how to react to that situation.

probably you would benefit from some study of the concept of exception handling in java, you will encounter it a lot.

The Java Tutorial does a pretty good job, but there's plenty of other sources too.

http://java.sun.com/docs/books/tutorial/essential/exceptions/index.html
 
Muzafar Ali
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fred Hamilton wrote:In addition to having the method throw the exception as you have done here, you should also learn about the try/catch method of handling exceptions.

Anyways, in this case it's all about how the program is supposed to react if the filename you specify in the program doesn't actually exist. You have to tell the program how to react to that situation.

probably you would benefit from some study of the concept of exception handling in java, you will encounter it a lot.

The Java Tutorial does a pretty good job, but there's plenty of other sources too.

http://java.sun.com/docs/books/tutorial/essential/exceptions/index.html

Yep you are right,
I will study on them,
Another question,
Look at this program.


Out put is

ENTER ROLL NO 1: 12
ENTER NAME1: ENTER NAME2: myName
NAME 1 IS:
NAME 2 IS: myName

any idea why it is behaving like that, i mean why it combines two statements together and is getting only one input!
(ENTER NAME1: ENTER NAME2 instead of this it has to show like this
ENTER NAME1:name1
ENTER NAME2:name2

if i am writing statement like this it works but not exceptiong spaces
name1=input.next();
name2=input.next();

is it possible to accept spaces and get inputs?
 
Campbell Ritchie
Sheriff
Pie
Posts: 48972
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please read the documentation for Scanner, find out what a "delimiter" is, what it uses as default delimiter, and also find out what happens when you push the enter key.
You may occasionally have to call the Scanner#next() method and discard the next token so as to keep your input Scanner and keyboard in step with each other.
 
Muzafar Ali
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Please read the documentation for Scanner, find out what a "delimiter" is, what it uses as default delimiter, and also find out what happens when you push the enter key.
You may occasionally have to call the Scanner#next() method and discard the next token so as to keep your input Scanner and keyboard in step with each other.

Thank you sir,
Sorry but can you modify my program and use delimiter in it ??

Thanks,
Muzafar
 
Campbell Ritchie
Sheriff
Pie
Posts: 48972
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It does nobody any good to have a direct alteration to their code; they don't learn anything like that.

When you read the API documentation, what did you not understand? Then we can explain it for you.
 
Muzafar Ali
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:It does nobody any good to have a direct alteration to their code; they don't learn anything like that.

When you read the API documentation, what did you not understand? Then we can explain it for you.


Sorry sir i will Learn from documentation myself .

Thanks,
Muzafar
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic