Hi iam writing an arraylist to a text file. It works fine but some unwanted characters and symbols also get printed along with it. I tried with List.clear() but doesnt work. can you please suggest a method to do that?
This is what i get :
¬í psr java.util.ArrayListxÒ™Ça I sizexp w t CRN:34565t
CR NUMBER:N/At SOW NAME:SWEXCELt "PARTNER SERVICE MANAGER:joe mathewt LBG SERVICE MANAGER:lee stevet TYPE OF CONTRACT:SOWt VALUE OF CONTRACT:34567t REMARKS:goodt WORK STATUS:Livet APPROVAL:Fully signed offt PLATFORM:ADM-WPMt MODEL:T&Mt START DATE:15-08-2012t END DATE:25-08-2012t CUMULATIVE VALUE:5645x
Also how to print each item in the arraylist in the new line? I tried arrayList.add("CRN"+":"+obj1+"\n"); doesnt work either.
Firstly, why are you using ArrayList? If you are generating output which is to be dumped in a file, it makes much sense to use StringBuilder etc. instead of ArrayList.
Secondly, if you are writing ArrayList object itself by using serialization mechanism (writeObject method), then it writes the actual object to file, which might not be readable by simply opening the file (i.e. the ArrayList is not written in text format). If you want to read it, you'll need to use readObject method.
If you simply want to write the text, then no need to go for serialization.