File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Register / Login


JavaRanch » Java Forums » Java » I/O and Streams
Reply 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...

This message was edited 1 time. Last update was at by pramod reddy

Ulf Dittmer
Marshal

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


Android appsImageJ pluginsJava web charts
Carey Brown
Ranch Hand

Joined: Nov 19, 2001
Posts: 123

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

Joined: Apr 30, 2003
Posts: 607


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......
 
 
subject: FileName to write to a .txt File
 
developer file tools