GeeCON Prague 2014*
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


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
Author

FileName to write to a .txt File

pramod reddy
Greenhorn

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

Joined: Mar 22, 2005
Posts: 42028
    
  64
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: 174

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
Greenhorn

Joined: Jan 10, 2008
Posts: 15
Thanks for your valuable suggestions......
i will go through it......
 
GeeCON Prague 2014
 
subject: FileName to write to a .txt File