GZIPInputStream reading line by line

The basic setup of decorators is like this: InputStream fileStream = new FileInputStream(filename); InputStream gzipStream = new GZIPInputStream(fileStream); Reader decoder = new InputStreamReader(gzipStream, encoding); BufferedReader buffered = new BufferedReader(decoder); The key issue in this snippet is the value of encoding. This is the character encoding of the text in the file. Is it “US-ASCII”, “UTF-8”, … Read more

Modify the content of a file using Java

I would start with closing reader, and flushing writer: public class FileReplace { List<String> lines = new ArrayList<String>(); String line = null; public void doIt() { try { File f1 = new File(“d:/new folder/t1.htm”); FileReader fr = new FileReader(f1); BufferedReader br = new BufferedReader(fr); while ((line = br.readLine()) != null) { if (line.contains(“java”)) line = … Read more

fileReader.readAsBinaryString to upload files

(Following is a late but complete answer) FileReader methods support FileReader.readAsBinaryString() is deprecated. Don’t use it! It’s no longer in the W3C File API working draft: void abort(); void readAsArrayBuffer(Blob blob); void readAsText(Blob blob, optional DOMString encoding); void readAsDataURL(Blob blob); NB: Note that File is a kind of extended Blob structure. Mozilla still implements readAsBinaryString() … Read more