File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Problem Using PrintWriter class ! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Problem Using PrintWriter class !" Watch "Problem Using PrintWriter class !" New topic
Author

Problem Using PrintWriter class !

Muzafar Ali
Ranch Hand

Joined: Jun 11, 2009
Posts: 34
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


~When You Learn Anything, Learn by Heart !
Muzafar Ali
Ranch Hand

Joined: Jun 11, 2009
Posts: 34
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

Joined: May 13, 2009
Posts: 679
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

Joined: Jun 11, 2009
Posts: 34
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

Joined: Oct 13, 2005
Posts: 38007
    
  22
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

Joined: Jun 11, 2009
Posts: 34
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

Joined: Oct 13, 2005
Posts: 38007
    
  22
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

Joined: Jun 11, 2009
Posts: 34
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem Using PrintWriter class !
 
Similar Threads
Keep getting this error and not sure why
Getting the average to display
getting java.lang.NoSuchMethodError: main error! thanks =)
Creating a method to average grades out
when i run my virtual machine just keeps going, but no output.