filereader

关于django中input标签中file类型

别等时光非礼了梦想. 提交于 2019-11-28 13:37:50
0825自我总结 关于django中input标签中file类型 1.input提交图片实时展示 <img src="/static/img/default.png" width="80" height="80" style="margin-left: 20px" id="id_img"> <input type="file" name="file" id="id_file"> <script> //当该控件发生变化,响应该事件 $("#id_file").change(function () { //alert(1) //取到文件对象 var file = $("#id_file")[0].files[0] //放到img控件上,借助于filereader 中间的东西,文件阅读器 //生成一个文件阅读器对象赋值给filereader var filereader = new FileReader() //把文件读到filereader对象中 //读文件需要时间,需要文件读完再去操作img //如果没这一步操作下面不一定变化 filereader.readAsDataURL(file) filereader.onload = function () { $("#id_img").attr('src', filereader.result) } }) </script> 2

Java IO

老子叫甜甜 提交于 2019-11-28 13:34:33
IO类 IO本身就是输入输出的意思,IO类就是为了与磁盘进行IO相关操作的工具、桥梁; IO类基本可以分成 字节流 和 字符流 ; 而既然是IO,那不管是哪个流都是分为输入和输出两大块 字节流 InputStream(抽象) (字节输入流) InputStream是所有字节输入流的抽象基类,提供字节输入的通用方法 基本方法: read() //从文件中读取数据的下一字节 read(byte[]) //从文件中读取一个数组量的字节 read(byte[], int, int) //从文件中读取限定位置数量的字节 注:当读取不到字节时会返回 -1 FileInputStream 该流是父类提供用于实例化的读取文件的输入流,能从指定文件中读取字节,从而读取文件内容 构造方法有两个: 需要实例化一个File文件对象 FileInputStream( File ) 不用实例化File对象 FileInputStream( String ) 使用方式 一个一个字节读取(效率慢) public static void main(String[] args) throws IOException { //创建一个字节输入流对象,必须明确数据源 File file = new File("c:\\file.txt"); FileInputStream fis = new

Load image into FileReader

倾然丶 夕夏残阳落幕 提交于 2019-11-28 12:35:30
I want to load an image from an url into filereader in order to obtain a data url of that image. I tried to search for the solution on google but i can only find solutions to read them from the file input on a local computer. If you want a usable data-URI representation of the image, then I suggest to load the image in a <img> tag, paint it on a <canvas> then use the .toDataURL() method of the canvas. Otherwise, you need to use XMLHttpRequest to get the image blob (set the responseType property on the XMLHttpRequest instance and get the blob from the .response property). Then, you can use the

输入输出流和顶级父类

丶灬走出姿态 提交于 2019-11-28 10:45:15
输入输出流分为:字符流 和 字节流 字节流: InputStream OutputStream (一切都是字节流) 字符流:Reader Writer(主要是强调功能,用来读取字符流的继承自Object) OutputtStream -----是一个超类,和抽象类 FileOutputStream -- 字节输出流 public class CopyDemo {// 字节流的演示 public static void main(String[] args) { try { // 创建输入输出--这都是字节流,但是中文需要字符流 FileInputStream inputStream = new FileInputStream("src\\main\\java\\com\\nowcoder\\Gday09\\test.jpg"); FileOutputStream outputStream = new FileOutputStream("src\\main\\java\\com\\nowcoder\\Gday09\\test0.jpg"); // 设定每次读取的字节数1024个字节 byte[] bytes = new byte[1024]; int length = 0; while ((length = inputStream.read(bytes))!= -1){ //

Filereader - upload same file again not working

旧城冷巷雨未停 提交于 2019-11-28 10:44:30
I have sth like drawing app. User can save projects and then load them. When I load first time one file (for e.g. project1.leds) make some changes in the app but no saving it and then again load same file (project1.leds) nothing happen. I cant load same file more than once. If I load another file, it's working. Code: $("#menu-open-file").change(function(e){ var data=[]; var file = null; file = e.target.files[0]; console.log(file) var reader = new FileReader(); reader.onload = function(e){ data=JSON.parse(reader.result); x=data[0].SIZE[0]; y=data[0].SIZE[1]; if(x==15) x=16; if(x==30) x=32; if(x

How to read a local (res/raw) file line by line?

徘徊边缘 提交于 2019-11-28 09:43:19
问题 I have a text file in my res/raw directory. I want to read the file line by line, but FileReader and BufferedReader fail, because of Android's security restriction. How else can I do it? 回答1: getResources().openRawResource() returns an InputStream that should be usable for line-by-line reading. 回答2: A DataInputStream allows you to do a readLine (along with a host of other operations); see DataInputStream Reference. 来源: https://stackoverflow.com/questions/3219150/how-to-read-a-local-res-raw

How to read XML file using FileReader javascript?

社会主义新天地 提交于 2019-11-28 09:12:12
问题 I need to get XML from a ODF file. I tried using FileReader readAsText and readAsBinaryString but its not working. FileReader readAsText returns some special characters for odf files. with readAsBinaryString var reader = new FileReader() reader.onloadend=function(e){ var data = e.target.result; //data is not in xml format var xml = str2xml(data); //getting error /* using DOM parser for xml parsing */ } reader.readAsBinaryString(file); How can get XML from ODF file using javascript FileReader?

How to read from files with Files.lines(…).forEach(…)?

两盒软妹~` 提交于 2019-11-28 09:08:45
I'm currently trying to read lines from a text only file that I have. I found on another stackoverflow( Reading a plain text file in Java ) that you can use Files.lines(..).forEach(..) However I can't actually figure out how to use the for each function to read line by line text, Anyone know where to look for that or how to do so? pardeep131085 Sample content of test.txt Hello Stack Over Flow com Code to read from this text file using lines() and forEach() methods. import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util

Convert Blob to binary string synchronously

元气小坏坏 提交于 2019-11-28 08:56:54
问题 I'm trying to put image in clipboard when user copies canvas selection: So I thought the right way would be to convert canvas tu dataURL, dataURL to blob and blob to binary string. Theoretically it should be possible to skip the blob, but I don't know why. So this is what I did: function copy(event) { console.log("copy"); console.log(event); //Get DataTransfer object var items = (event.clipboardData || event.originalEvent.clipboardData); //Canvas to blob var blob = Blob.fromDataURL(_this

缓冲流之字符缓冲流

廉价感情. 提交于 2019-11-28 08:22:03
字符缓冲流 字符缓冲输入流 BufferedReader 字符缓冲输出流 BufferedWriter 完成文本数据的高效的写入与读取的操作 1 字符缓冲输出流 BufferedWriter void newLine() 根据当前的系统,写入一个换行符 public static void method01() throws IOException{ //明确目的地 FileWriter fw =new FileWriter("E:\\java\\demo01.txt"); //添加缓冲流 BufferedWriter bw=new BufferedWriter(fw); //写入文件 // windows: \r\n // linux: \n // newline(); System.out.println(System.in); bw.write("你好"); bw.newLine(); bw.flush(); bw.write("java"); bw.newLine(); bw.flush(); bw.write("中国"); bw.newLine(); //释放资源 bw.close(); } 2 字符缓冲输入流BufferedReader 从字符输入流中读取文本,缓冲各个字符,从而实现字符、数组和行的高效读取。 public String readLine()