Questions tagged «filereader»

9
我需要同时关闭FileReader和BufferedReader吗?
我正在使用包裹在FileReader周围的BufferedReader读取本地文件: BufferedReader reader = new BufferedReader(new FileReader(fileName)); // read the file // (error handling snipped) reader.close(); 我需要close()的FileReader为好,或将包装处理这个问题?我看过代码,人们在其中执行以下操作: FileReader fReader = new FileReader(fileName); BufferedReader bReader = new BufferedReader(fReader); // read the file // (error handling snipped) bReader.close(); fReader.close(); 从Servlet调用此方法,并且我想确保我没有打开任何句柄。


8
java.io.PrintWriter和java.io.BufferedWriter之间的区别?
请浏览以下代码: // A.class File file = new File("blah.txt"); FileWriter fileWriter = new FileWriter(file); PrintWriter printWriter = new PrintWriter(fileWriter); // B.class File file = new File("blah.txt"); FileWriter fileWriter = new FileWriter(file); BufferedWriter bWriter = new BufferedWriter(fileWriter); 这两种方法有什么区别? 我们何时应该在BufferedWriter上使用PrintWriter?


5
GZIPInputStream逐行读取
我有一个.gz格式的文件。读取此文件的Java类是GZIPInputStream。但是,此类不会扩展Java的BufferedReader类。结果,我无法逐行读取文件。我需要这样的东西 reader = new MyGZInputStream( some constructor of GZInputStream) reader.readLine()... 我虽然创建了扩展java的Reader或BufferedReader类并使用GZIPInputStream作为其变量之一的类。 import java.io.BufferedReader; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.Reader; import java.util.zip.GZIPInputStream; public class MyGZFilReader extends Reader { private GZIPInputStream gzipInputStream = null; char[] buf = new char[1024]; @Override public void close() throws IOException { gzipInputStream.close(); } public MyGZFilReader(String …

3
fileReader.readAsBinaryString上传文件
尝试使用fileReader.readAsBinaryString通过AJAX将PNG文件上传到服务器,并精简代码(fileObject是包含我的文件信息的对象); var fileReader = new FileReader(); fileReader.onload = function(e) { var xmlHttpRequest = new XMLHttpRequest(); //Some AJAX-y stuff - callbacks, handlers etc. xmlHttpRequest.open("POST", '/pushfile', true); var dashes = '--'; var boundary = 'aperturephotoupload'; var crlf = "\r\n"; //Post with the correct MIME type (If the OS can identify one) if …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.