filereader

HTML5 FIle API: Security Error while reading a file

无人久伴 提交于 2019-12-18 19:46:16
问题 Problem solved, read comment The third problem I have with the HTML5 File API: I still use Chrome 12 on Mac OS X Snow Leopard and I'm still trying to read files with the HTML5 File API, but FileHandler.error() get called because a "SECURITY_ERR" occurres. The file I try to read is a regular .txt file from my desktop, but it neither works with other files although I can open them with regular applications. function FileHandler(files, action) { console.log('FileHandler called.'); this.files =

html5 fileReader — how to only read the first N characters of a file?

筅森魡賤 提交于 2019-12-18 18:55:08
问题 Currently I use a pattern like the following to read the first 3 characters of a series of files: var files = e.dataTransfer.files; for (var i = 0, f; f = files[i]; i++) { var fr = new FileReader(); fr.onload = function(e) { var first_three_chars = e.target.result.substr(0,3); } fr.readAsText(f); } The trouble is that I'm only interested in the first 3 characters of the file, whereas this method reads the entire file, wasting lots of memory and time. How can I quickly iterate over the files,

io 流demo

﹥>﹥吖頭↗ 提交于 2019-12-18 03:38:18
/* * 需求:作业:将c盘的一个文本文件复制到d盘。 * * 思路: * 1,需要读取源, * 2,将读到的源数据写入到目的地。 * 3,既然是操作文本数据,使用字符流。 * */ public class CopyTextTest { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { //1,读取一个已有的文本文件,使用字符读取流和文件相关联。 FileReader fr = new FileReader("IO流_2.txt"); //2,创建一个目的,用于存储读到数据。 FileWriter fw = new FileWriter("copytext_1.txt"); //3,频繁的读写操作。 int ch = 0; while((ch=fr.read())!=-1){ fw.write(ch); } //4,关闭流资源。 fw.close(); fr.close(); } } public class CopyTextTest_2 { private static final int BUFFER_SIZE = 1024; /** * @param args */ public static void main

HTML5 File API: get File object within FileReader callback

北慕城南 提交于 2019-12-17 23:39:15
问题 With the new File API in Javascript you can read files in Javascript to create dataURLs to show clientside pictures clientside. I'm wondering if you can reach the File object within the FileReader's onload callback. I will illustrate this with an example: var div = document.createElement('div'); div.ondrop = function(e) { e.preventDefault(); e.stopPropagation(); var files = e.dataTransfer.files; for ( var i=0; i<files.length; i++ ) { var file = files[i]; // this is the file I want!! var

How to get the filename from the Javascript FileReader?

孤街浪徒 提交于 2019-12-17 19:12:08
问题 I'm using the Javascript FileReader to load an image in the browser: e = e.originalEvent; e.dataTransfer.dropEffect = 'copy'; this.documentFile = e.dataTransfer.files[0]; var reader = new FileReader(); reader.onloadend = function () { if (reader.result) { console.log(reader); $('#theImage').attr('src', reader.result); } }; reader.readAsDataURL(this.documentFile); This works fine. I now want to get the original filename of the image, but I've got no clue how and looking around the internet I

Using Javascript FileReader with huge files

拥有回忆 提交于 2019-12-17 18:42:04
问题 I have a problem using the Javascript FileRead trying to read huge files. For example, I have a text file of 200mb and everytime I read this file the code stops working. Its possible to read the text file, but for example ONLY the first 10 lines or stop reading after 10mb? This is my code: var file = form.getEl().down('input[type=file]').dom.files[0]; var reader = new FileReader(); reader.onload = (function(theFile) { return function(e) { data = e.target.result; form.displayedData=data; }; })

Posting File Input as FileReader Binary Data through AJAX Post

徘徊边缘 提交于 2019-12-17 15:34:55
问题 I am trying to post an attachment uploaded to an HTML file input to a web page through a rest API. The API documentation states that the post is a straight binary content as the body of the HTTP request, not a form file upload. My code is as follows: $('#_testButton').bind('click', function () { var file = document.getElementById('_testFile').files[0] var reader = new FileReader(); reader.onload = function () { $.ajax({ url: '/attachmentURL', type: 'POST', data: reader.result }) } reader

File,FileInputStream,FileReader,InputStreamReader,BufferedReader

时光怂恿深爱的人放手 提交于 2019-12-17 11:44:44
File,FileInputStream,FileReader,InputStreamReader,BufferedReader 使用 Java 操作文本文件的方法详解 http://java.ccidnet.com/art/3737/20041108/523627_1.html FileReader 是什么类?和 FileInputStream 有什么不同??? http://book.hackbase.com/ask2/ask107572.htm 自己的整理和领会: 引言: C语言只需要一个File*就可以了,与C不同,java有一系列流类型,其数量超过60种。类库的设计者声称:“有足够的理由为用户提供丰富的流类型的选择:这样做可以减少程序的错误。”例如,在C语言种,许多人认为“将输出流写入一个只读模式的文件”是很常见的错误。(事实上,这并不常见。)我们认为在C++语言中,流接口设计者避免程序出错的主要“工具”是小心谨慎的态度,在java语言中更是如此。流库的高度复杂性迫使程序设计人员谨小慎微。 1.File类 1)File 类介绍(《 core java 》638 页) File 类封装了对用户机器的文件系统进行操作的功能。例如,可以用 File 类获得文件上次修改的时间移动,或者对文件进行删除、重命名。换句话说,流类关注的是文件内容,而 File

Difference between java.io.PrintWriter and java.io.BufferedWriter?

半世苍凉 提交于 2019-12-17 10:18:22
问题 Please look through code below: // 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); What is the difference between these two methods? When should we use PrintWriter over BufferedWriter? 回答1: The API reference for BufferedWriter and PrintWriter detail the

Looping through files for FileReader, output always contains last value from loop

烂漫一生 提交于 2019-12-17 07:07:10
问题 I'm using FileReader API to read files on local. <input type="file" id="filesx" name="filesx[]" onchange="readmultifiles(this.files)" multiple="" /> <script> function readmultifiles(files) { var ret = ""; var ul = document.querySelector("#bag>ul"); while (ul.hasChildNodes()) { ul.removeChild(ul.firstChild); } for (var i = 0; i < files.length; i++) //for multiple files { var f = files[i]; var name = files[i].name; alert(name); var reader = new FileReader(); reader.onload = function(e) { // get