filereader

Read binary data from an image and save it with JavaScript

ぃ、小莉子 提交于 2019-12-03 08:22:06
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 conversion which makes the binary data incorrect? To have a look at my demo application I made a fiddle .

Speed Up download time

喜欢而已 提交于 2019-12-03 08:21:16
I have 40 MB file in server and i am downloading my file using HttpURLConnection c = (HttpURLConnection) u.openConnection(); c.setRequestMethod("GET"); c.setDoOutput(true); c.connect(); FileOutputStream f = new FileOutputStream(new File("trips.xml")); InputStream in = c.getInputStream(); byte[] buffer = new byte[1024]; int len1 = 0; while ( (len1 = in.read(buffer)) != -1 ) { f.write(buffer,0, len1); this code seems working fine but it is taking too long. is their any way I can make this process faster. /minhaz This very ugly hack which might give you a faster download time, or maybe it doesn't

Read id3 v2.4 tags with native Chrome Javascript/FileReader/DataView

假装没事ソ 提交于 2019-12-03 07:27:48
问题 Based on the answer of ebidel, one can read id3v1 tags by using jDataView: document.querySelector('input[type="file"]').onchange = function (e) { var reader = new FileReader(); reader.onload = function (e) { var dv = new jDataView(this.result); // "TAG" starts at byte -128 from EOF. // See http://en.wikipedia.org/wiki/ID3 if (dv.getString(3, dv.byteLength - 128) == 'TAG') { var title = dv.getString(30, dv.tell()); var artist = dv.getString(30, dv.tell()); var album = dv.getString(30, dv.tell(

Difference between buffered reader and file reader and scanner class [duplicate]

冷暖自知 提交于 2019-12-03 06:05:08
问题 This question already has answers here : Scanner vs. BufferedReader (12 answers) Closed 5 years ago . Can anyone explain me the difference between the class BufferedReader , FileReader and Scanner ? and which one to use when I want to read a text file? 回答1: Well: FileReader is just a Reader which reads a file, using the platform-default encoding (urgh) BufferedReader is a wrapper around another Reader , adding buffering and the ability to read a line at a time Scanner reads from a variety of

第十周作业课程总结

耗尽温柔 提交于 2019-12-03 05:18:54
一、Java字符流的使用: 字符输入/输出流、字符文件和字符缓冲区的输入/输出流 java 中字节流的功能十分强大,几乎可以直接或间接地处理任何类型的输入/输出操作。 1、字符输入流: Reader 类是所有字符流输入类的父类,该类定义了许多方法,这些方法对所有子类都是有效的。 Reader 类的常用子类如下: CharArrayReader 类:将字符数组转换为字符输入流,从中读取字符。 StringReader 类:将字符串转换为字符输入流,从中读取字符。 BufferedReader 类:为其他字符输入流提供读缓冲区。 PipedReader 类:连接到一个 PipedWriter。 InputStreamReader 类:将字节输入流转换为字符输入流,可以指定字符编码。 与 InputStream 类相同,在 Reader 类中也包含 close() 、 mark() 、 skip() 和 reset() 等方法. Reader类中的 read() 方法 方法名及返回值类型 说明 int read() 从输入流中读取一个字符,并把它转换为 0~65535 的整数。如果返回 -1, 则表示已经到了输入流的末尾。为了提高 I/O 操作的效率,建议尽量使 用下面两种 read()方法 int read(char[] cbuf) 从输入流中读取若干个字符,并把它们保存到参数

BBS小项目疑问点及解决办法(持续更新)

隐身守侯 提交于 2019-12-03 05:15:39
1. Python使用requirement.txt安装类库 ​ 今天偶然看到这个文件,但是又忘记是干什么的了,于是又查了一下,现在做一个简单地总结 ​ 首先你要明白python是一个调包侠,所以在导入第三包的时候,需要设置相关环境及必要组件,基于此,该文件便出现了。 ​ 这个文件顾名思义,记录的是所有依赖包及其精准的版本号,这样在新环境部署的时候就会方便很多, 例如:requests == 1.2.0 Flask == 0.10.1 ​ 具体使用方式见这篇博客 Python项目生成requirement.txt 2. 表字段中null和blank的区别 null 是针对数据库而言,如果 null=True, 表示数据库的该字段可以为空。 blank 是针对表单的,如果 blank=True,表示你的表单填写该字段的时候可以不填,比如 admin 界面下增加 model 一条记录的时候。直观的看到就是该字段不是粗体 通俗点说,该字段null=true后,你进行插入,修改操作时可以为空,然后Django把空值转换成null存在数据库中,而blank只是在表单验证的时候会检测你是否可以为空 参考[ 关于Django字段类型中 blank和null的区别 ] 3. auth_now_add和auth_now auto_now_add=True时为添加时的时间,更新对象时不会有变动。

第十周编程总结

怎甘沉沦 提交于 2019-12-03 04:06:07
题目:将奇数位的小写字母传化为大写字母 实验代码: package Bian; import java.io.File; import java.io.FileOutputStream; import java.io.OutputStream; import java.util.Scanner; public class A { public static void main(String[] args) throws Exception { File f = new File("f:" + File.separator + "test.txt");//定位文件位置 OutputStream out = null; out = new FileOutputStream(f); Scanner in = new Scanner(System.in);//输入 System.out.println("请输入:"); String str = in.nextLine(); byte b[] = str.getBytes();//转为数组 for (int i = 0; i < b.length; i++) { if (i % 2 == 0 && b[i] >= 'a' && b[i] <= 'z') {//判定条件 b[i] = (byte) (b[i] - 32); } out

Using $(this) with FileReader() to target result

馋奶兔 提交于 2019-12-03 04:04:51
I'm trying to show an ajax preview of an image from a file input. Easy enough using FileReader() but I'm using it with a loop so I when it's time to place the result inside an image source, I need to use $(this) to target the loop item of the input. That doesn't even make sense to me so here we go. We have a loop.. <li> <input type="file" class="image" /> <img src="" class="preview" /> </li> <li> <input type="file" class="image" /> <img src="" class="preview" /> </li> <li> <input type="file" class="image" /> <img src="" class="preview" /> </li> So now lets say the second input is choosen and

Using FileReader.readAsArrayBuffer() on changed files in Firefox

六眼飞鱼酱① 提交于 2019-12-03 02:49:48
I'm running into an odd problem using FileReader.readAsArrayBuffer that only seems to affect Firefox (I tested in the current version - v40). I can't tell if I'm just doing something wrong or if this is a Firefox bug. I have some JavaScript that uses readAsArrayBuffer to read a file specified in an <input> field. Under normal circumstances, everything works correctly. However, if the user modifies the file after selecting it in the <input> field, readAsArrayBuffer can get very confused. The ArrayBuffer I get back from readAsArrayBuffer always has the length that the file was originally. If the

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

﹥>﹥吖頭↗ 提交于 2019-12-03 02:34:48
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 issue. I Suggest to use the blob api, I've found the same problem and I solved like that: var html = <svg