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!

Exception in thread "main" java.lang.NullPointerException

807589Sep 29 2008 — edited Sep 29 2008
I wanted to read text from standard input and write the same to a file named write.txt..
am getting following error

Exception in thread "main" java.lang.NullPointerException
at java.io.Writer.write(Writer.java:140)
at readdstinpwritefile.ReaddStinpWriteFile.main(ReaddStinpWriteFile.java:35)


public static void main(String[] args)throws IOException {
BufferedWriter bw= new BufferedWriter(new FileWriter("d:/JAVA/io/write.txt"));
BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
String name="";
System.out.println("Enter ur name");
name=br.readLine();
bw.write(name);
bw.close();
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 27 2008
Added on Sep 29 2008
16 comments
789 views