filereader

Html5 学习系列(四)文件操作API

烈酒焚心 提交于 2019-12-21 04:54:26
引言 在之前我们操作本地文件都是使用flash、silverlight或者第三方的activeX插件等技术,由于使用了这些技术后就很难进行跨平台、或者跨浏览器、跨设备等情况下实现统一的表现,从另外一个角度来说就是让我们的web应用依赖了第三方的插件,而不是很独立,不够通用。在HTML5标准中,默认提供了操作文件的API让这一切直接标准化。有了操作文件的API,让我们的Web应用可以很轻松的通过JS来控制文件的读取、写入、文件夹、文件等一系列的操作,让Web应用不再那么蹩脚,而之前Web应用如果不借助第三方插件,那就是个shit!但是最新的标准中大部分浏览器都已经实现了文件的读取API,文件的写入,文件和文件夹的最新的标准刚制定完毕,相信后面随着浏览器的升级这些功能肯定会实现的非常好,接下来我主要给大家介绍文件读取的几个API。 几个重要的JS对象 1):FileList对象 它是File对象的一个集合,在Html4标准中文件上传控件只接受一个文件,而在新标准中,只需要设置multiple,就支持多文件上传,所以从此标签中获取的files属性就是FileList对象实例。demo:<input type="file" multiple="multiple" name="fileDemo" id="fileDemo" /> ;下面是关于FileList对象的API的原型:

Copying the Contents of One text file to Another in Java

谁说我不能喝 提交于 2019-12-21 04:29:17
问题 I am trying to copy the contents of one text file ("1.txt") which contains 2-3 integer numbers (ex: 1 2 3) to another text file ("2.txt") but I am getting the following error upon compilation import java.io.*; class FileDemo { public static void main(String args[]) { try { FileReader fr=new FileReader("1.txt"); FileWriter fw=new FileWriter("2.txt"); int c=fr.read(); while(c!=-1) { fw.write(c); } } catch(IOException e) { System.out.println(e); } finally() { fr.close(); fw.close(); } } }

Read binary data from an image and save it with JavaScript

◇◆丶佛笑我妖孽 提交于 2019-12-21 01:58:34
问题 I want to read the binary data of an image and then save it again to my local disk with JavaScript. I wrote a small demo that shows this use-case. To read the file I use readAsBinaryString from the File Reader API (HTML5) to get the binary data. I write the binary string into a textfield from which I then read the data again to write it to a file. If I save the file my images (I tested several JPEGs) are broken so you cannot see anything useful. Can it be that "readAsBinaryString" makes a

Is there an alternative for File() constructor for Safari and IE?

喜夏-厌秋 提交于 2019-12-20 12:16:43
问题 I am using the File() constructor for creating file object for uploading a blob file to the server. The following code works fine for Chrome, but fails for Safari and Internet Explorer. image_url = new File([blob],file_name,{type: mimeString}); The code is breaking at this line and getting this error in console "FileConstructor is not a constructor" (evaluating 'new File([blob],file_name,{type: mimeString})') Using the FileReader API is an alternative to this but I am not able to fix this

Is there an alternative for File() constructor for Safari and IE?

为君一笑 提交于 2019-12-20 12:16:13
问题 I am using the File() constructor for creating file object for uploading a blob file to the server. The following code works fine for Chrome, but fails for Safari and Internet Explorer. image_url = new File([blob],file_name,{type: mimeString}); The code is breaking at this line and getting this error in console "FileConstructor is not a constructor" (evaluating 'new File([blob],file_name,{type: mimeString})') Using the FileReader API is an alternative to this but I am not able to fix this

Ⅶ期Day14:图片上传及预览/访问器属性/classList兼容性

 ̄綄美尐妖づ 提交于 2019-12-20 10:52:00
访问器属性 var testObj = { link:'ppp' }; var testOBJ2 = Object.create(testObj,{ //数据属性 name:{ value:'laney', writable:true,//可以修改文本,false不可以修改文本 enumerable:false, configurable:true }, country:{ value:'china', writable:true, enumerable:true, configurable:true }, //访问器属性 4- infoPerson:{ get(){ return this.name + 'come form ' +this.country }, set(name,country){ this.name = name this.country = country }, enumerable:true, configurable:true } }) classList 兼容IE10以下 HTML <div id="classListDom" class="test name ds">ssss</div> JS // classList , 兼容问题 ,支持IE10以上 // babel-polyfill.js // polyfill为旧浏览器提供兼容性支持 //

Reading in a local csv file in javascript? [closed]

时间秒杀一切 提交于 2019-12-20 08:45:26
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 4 years ago . [EDIT] I solved the problem using D3 , nevermind thanks! So I have a csv file that looks something like this, and I need to import a local csv file into my client side javascript: "L.Name", "F.Name", "Gender", "School Type", "Subjects" "Doe", "John", "M", "University", "Chem I,

Convert local image blob to base64, in PHP

橙三吉。 提交于 2019-12-20 05:49:28
问题 I'm working on an (HTML) form for an internal tool. Users can fill data out about an issue and attach screenshots. This form is then submitted via ajax to PHPMailer to be sent. The issue is with the screenshots. Due to system limitations I'm unable to have the users actually upload the files to the server. Currently, I'm using HTML5 filereader to select the files. I then convert the image blobs to base64 and send them to PHPMailer, to be converted to attachments. This is actually working

Different behavior of XmlPullParser.getInputEncoding() on API11+ and pre-API11 versions of Android

你说的曾经没有我的故事 提交于 2019-12-19 11:17:58
问题 I am developing a new feature for my android app to enable data backup and restore. I am using XML files to backup data. This is a piece of code that sets encoding for an output file: XmlSerializer serializer = Xml.newSerializer(); FileWriter fileWriter = new FileWriter(file, false); serializer.setOutput(fileWriter); serializer.startDocument("UTF-8", true); [... Write data to the file....] This is how I try to import data from an XML file. First, I check if the encoding is correct:

Different behavior of XmlPullParser.getInputEncoding() on API11+ and pre-API11 versions of Android

我的未来我决定 提交于 2019-12-19 11:17:30
问题 I am developing a new feature for my android app to enable data backup and restore. I am using XML files to backup data. This is a piece of code that sets encoding for an output file: XmlSerializer serializer = Xml.newSerializer(); FileWriter fileWriter = new FileWriter(file, false); serializer.setOutput(fileWriter); serializer.startDocument("UTF-8", true); [... Write data to the file....] This is how I try to import data from an XML file. First, I check if the encoding is correct: