[android-developers] Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required!
Hi The above error occurs when I do the following. I have a text file with multiple lines of data. Within my application I come across the need to replace a line from the file with a new one. I am using BufferedReader with a fixed size (50k) to read the file into as below: FileReader input_redo = new FileReader(redo); BufferedReader reader = new BufferedReader(input_redo); String line = , oldtext = ; while((line = reader.readLine()) != null) { oldtext += line + \r\n; } reader.close(); String newtext = oldtext.replaceAll(Hello how are you, Have I met you before?); FileWriter writer = new FileWriter(/sdcard/data/replace.txt); writer.write(newtext); writer.close(); Could anyone please help me out with this error? I know the device is running out of memory bcoz of the buffer size or something but don't know a work around for this. Please help Abhi -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required!
This isn't an error, it's just a message to inform you it is better to specify the size of the buffer you need in the constructor. Abhi wrote: String line = , oldtext = ; while((line = reader.readLine()) != null) { oldtext += line + \r\n; } Don't do that, use a StringBuilder and StringBuilder#append() instead. String concatenation like the way you are doing it slows things down and creates more objects. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en