How to reuse a File Handler to open multiple files -


i have write piece of code can't predetermine filename creating.

due keep single file handler. close this. create file using same file handler.

sample code:

public void sample(string input)   {       // value of string changes dynamically                                                 // , accordingly new file needs created.      string filename = input;      file file = new file(filename);     filewriter fw = new filewriter(file);     bufferedwriter bw= new bufferedwriter(fw);      // code write contents file.     bw.close(); } 

now, invoking function "sample" multiple times different file names.

when tried above sample code, getting nullpointerexception. can guide me going wrong?

regards,
harish


Comments

Popular posts from this blog

android - How to save instance state of selected radiobutton on menu -

python 3 IndexError: list index out of range -

IF statement in MySQL trigger -