permaculture playing cards*
The moose likes I/O and Streams and the fly likes FileName to write to a .txt File Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "FileName to write to a .txt File" Watch "FileName to write to a .txt File" New topic

FileName to write to a .txt File

pramod reddy

Joined: Jan 10, 2008
Posts: 15
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

Joined: Mar 22, 2005
Posts: 41124
Which line causes the exception? Which object is null?

Ping & DNS - my free Android networking tools app
Carey Brown
Ranch Hand

Joined: Nov 19, 2001
Posts: 173

Line 77 will potentially set 'files' to null.
Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

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

Joined: Jan 10, 2008
Posts: 15
Thanks for your valuable suggestions......
i will go through it......
I agree. Here's the link:
subject: FileName to write to a .txt File
Similar Threads
File IO - BufferedWriter/FileWriter
what's wrong with this,.. Date, Calendar Stuff.. ????
Reading first 10 lines from a file and writing it into another file
Current Date Comparison
Buffered Writer problem