• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

FileName to write to a .txt File

 
pramod reddy
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hai,
i am new to java.
i am developing an application, where the user enters a file or directory name and if it is a file ,then i have to write the filename to the .txt file.
i am using recusive method to test whther it is a file or directory, and if it is a file i want to write the name of the file to the .txt file, while running the below code i am getting the null pointer exception..
i think my declaration of BufferedWriter is wrong...
any suggestions are welcome.

and my code is here...

 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which line causes the exception? Which object is null?
 
Carey Brown
Ranch Hand
Pie
Posts: 1317
15
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Line 77 will potentially set 'files' to null.
 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

BufferedWriter will never print anything to the file until you call flush() on it.

you may want to handle cases in the modify method where your file doesn't match either of those if statements
 
pramod reddy
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your valuable suggestions......
i will go through it......
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic