File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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: 39544
Which line causes the exception? Which object is null?

Ping & DNS - updated with new look and Ping home screen widget
Carey Brown
Ranch Hand

Joined: Nov 19, 2001
Posts: 170

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
Buffered Writer problem
what's wrong with this,.. Date, Calendar Stuff.. ????
File IO - BufferedWriter/FileWriter
Reading first 10 lines from a file and writing it into another file
Current Date Comparison