filereader

GZIPInputStream reading line by line

感情迁移 提交于 2019-11-26 11:52:13
问题 I have a file in .gz format. The java class for reading this file is GZIPInputStream. However, this class doesn\'t extend the BufferedReader class of java. As a result, I am not able to read the file line by line. I need something like this reader = new MyGZInputStream( some constructor of GZInputStream) reader.readLine()... I though of creating my class which extends the Reader or BufferedReader class of java and use GZIPInputStream as one of its variable. import java.io.BufferedReader;

Do I need to close() both FileReader and BufferedReader?

陌路散爱 提交于 2019-11-26 11:40:48
I'm reading a local file using a BufferedReader wrapped around a FileReader: BufferedReader reader = new BufferedReader(new FileReader(fileName)); // read the file // (error handling snipped) reader.close(); Do I need to close() the FileReader as well, or will the wrapper handle that? I've seen code where people do something like this: FileReader fReader = new FileReader(fileName); BufferedReader bReader = new BufferedReader(fReader); // read the file // (error handling snipped) bReader.close(); fReader.close(); This method is called from a servlet, and I'd like to make sure I don't leave any

Modify the content of a file using Java

五迷三道 提交于 2019-11-26 11:25:05
问题 I want to delete some content of file using java program as below. Is this the write method to replace in the same file or it should be copied to the another file. But its deleting the all content of the file. class FileReplace { ArrayList<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

Change specific value in CSV file via Python

徘徊边缘 提交于 2019-11-26 10:31:34
I need the way to change specific value of the column of csv file. For example I have csv file: "Ip","Sites" "127.0.0.1",10 "127.0.0.2",23 "127.0.0.3",50 and I need to change value 23 to 30 of the "127.0.0.2". I use csv library: import csv Appreciate any help as I'm new in Python. Thanks! Diego Navarro This is the solution opening the csv file, changing the values in memory and then writing back the changes to disk. r = csv.reader(open('/tmp/test.csv')) # Here your csv file lines = list(r) Content of lines: [['Ip', 'Sites'], ['127.0.0.1', '10'], ['127.0.0.2', '23'], ['127.0.0.3', '50']]

HTML5 FileReader how to return result?

纵然是瞬间 提交于 2019-11-26 09:25:03
问题 I use JS FileReader. I want to get result after file reading operation and work with this data. FileReader is asynchronous and I don\'t know when result is ready. How to get it done right? $(document).ready(function(){ $(\'#file_input\').on(\'change\', function(e){ var res = readFile(this.files[0]); //my some manipulate with res $(\'#output_field\').text(res); }); }); function readFile(file){ var reader = new FileReader(), result = \'empty\'; reader.onload = function(e) { result = e.target

Chrome FileReader

给你一囗甜甜゛ 提交于 2019-11-26 08:09:08
问题 Can someone give me an example of using the FileReader API go get contents of a file in chrome? It seems to be returning undefined for me. <!doctype html> <html> <script> function handle_files(files) { console.log(files) reader = new FileReader() ret = [] for (i = 0; i < files.length; i++) { file = files[i] console.log(file) text = reader.readAsText(file) //readAsdataURL console.log(text) //undefined ret.push(text) } console.log(ret) // [undefined] } </script> <body> FileReader Test <input

javascript FileReader - parsing long file in chunks

怎甘沉沦 提交于 2019-11-26 07:23:19
问题 I have long file I need to parse. Because it\'s very long I need to do it chunk by chunk. I tried this: function parseFile(file){ var chunkSize = 2000; var fileSize = (file.size - 1); var foo = function(e){ console.log(e.target.result); }; for(var i =0; i < fileSize; i += chunkSize) { (function( fil, start ) { var reader = new FileReader(); var blob = fil.slice(start, chunkSize + 1); reader.onload = foo; reader.readAsText(blob); })( file, i ); } } After running it I see only the first chunk

Specific difference between bufferedreader and filereader

一笑奈何 提交于 2019-11-26 06:56:54
问题 I would like to know the specific difference between BufferedReader and FileReader . I do know that BufferedReader is much more efficient as opposed to FileReader , but can someone please explain why (specifically and in detail)? Thanks. 回答1: In simple manner: A FileReader class is a general tool to read in characters from a File. The BufferedReader class can wrap around Readers, like FileReader, to buffer the input and improve efficiency. So you wouldn't use one over the other, but both at

filereader api on big files

折月煮酒 提交于 2019-11-26 06:24:59
问题 My file reader api code has been working good so far until one day I got a 280MB txt file from one of my client. Page just crashes straight up in Chrome and in Firefox nothing happens. // create new reader object var fileReader = new FileReader(); // read the file as text fileReader.readAsText( $files[i] ); fileReader.onload = function(e) { // read all the information about the file // do sanity checks here etc... $timeout( function() { // var fileContent = e.target.result; // get the first

What is the difference between Reader and InputStream?

删除回忆录丶 提交于 2019-11-26 05:23:50
问题 What is the difference between Reader and InputStream? And when to use what? If I can use Reader for reading characters why I will use inputstream, I guess to read objects? 回答1: An InputStream is the raw method of getting information from a resource. It grabs the data byte by byte without performing any kind of translation. If you are reading image data, or any binary file, this is the stream to use. A Reader is designed for character streams. If the information you are reading is all text,