Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to get Exception message as String from e.printStackTrace()

807589Aug 1 2008 — edited Aug 1 2008
hi ,
* In the below code it will throw FileNotFoundException ...
* How can i get that Exception message as String from e.printStackTrace() method....
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;


public class ExceptionMessage {

	public static void main(String[] args) {
		FileInputStream fil_inp;
		try {
			fil_inp = new FileInputStream(new File("D:/java/test.txt"));
			System.out.println(fil_inp.available());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
Thanks in advance,
JavaImran
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 29 2008
Added on Aug 1 2008
8 comments
2,259 views