filereader

Java学习笔记-文件读写和Json数组

本小妞迷上赌 提交于 2019-11-30 12:43:01
Java文件读写 Java中I/O流对文件的读写有很多种方法,百度后主要看了以下三种 第一种方式:使用FileWriter和FileReader,对文件内容按字符读取,代码如下 String dir = "E:\\soft\\aaa\\a.txt"; File file = new File(dir); //如果文件不存在,创建文件 if (!file.exists()) file.createNewFile(); //创建FileWriter对象 FileWriter writer = new FileWriter(file); //向文件中写入内容 writer.write("the first way to write and read"); writer.flush(); writer.close(); //创建FileReader对象,读取文件中的内容 FileReader reader = new FileReader(file); char[] ch = new char[100]; reader.read(ch); for(char c:ch) { System.out.print(c); } System.out.println(); reader.close(); 第二种方式:使用包装类BuffredReader和BufferedWriter

Get/set file encoding with javascript's FileReader

£可爱£侵袭症+ 提交于 2019-11-30 12:35:32
问题 I am struggling with the following problem. Using javascript I would like to change the character set of a file content and display this content to the user. I have an input:file form. On change I am reading the content $('#form input:file').change(function(event){ file = this.files[0]; reader = new FileReader(); reader.onload = function(event) { result = event.target.result.replace(/\n/g,'<br />'); $('#filecontents').html(result); }); reader.readAsText(file); }) The file is in Windows-1251.

How to get the filename from the Javascript FileReader?

妖精的绣舞 提交于 2019-11-30 11:05:41
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 can't find anything either? Does anybody know how I can get the filename through the FileReader? All

How to read a text file into jtextarea in Java Swing

时光毁灭记忆、已成空白 提交于 2019-11-30 09:24:58
问题 Here is my code: try { String textLine; FileReader fr = new FileReader("ad.txt"); BufferedReader reader = new BufferedReader(fr); while((textLine=reader.readLine()) != null) { textLine = reader.readLine(); jTextArea1.read(reader, "jTextArea1"); } } catch (IOException ioe) { System.err.println(ioe); System.exit(1); } And my .txt file contains the following: contig00001 length=586 numreads=4 CGGGAAATTATCcGCGCCTTCACCGCCGCCGGTTCCACCGACGAACGGATACTGCGtGaa

slice large file into chunks and upload using ajax and html5 FileReader

a 夏天 提交于 2019-11-30 06:47:08
问题 What I want to implement is: In the front end, I use the html5 file api to read the file, and then upload the file's content to the php backend using ajax, and it's ok if the filesize is small. However,if the file is big enough, it causes chrome to crash. So I split the large file into chunks using file.slice, when all chunks are uploaded to the php, merge the chunks into a single complete one. the code is as follows: the front end: <style> #container { min-width:300px; min-height:200px;

根据后端的文件数据流,在前端形成下载文件(不是直接通过浏览器下载)

久未见 提交于 2019-11-30 05:45:13
实现原理:定义的接口不是下载文件的路径,而是通过API可以获得文件的内容,由前端把内容写入到文件中,这种方法是通过获取文件信息,在网页上利用click事件,创建一个文件,然后将文件信息写入到文件中,然后保存。 主要用到了JavaScript中的Blob对象和HTML5中的FileReader对象。代码如下: python/django: from django.http import HttpResponse from django.views.decorators.csrf import csrf_exempt import csv from django.http import StreamingHttpResponse #下载 @csrf_exempt def download(request): # Create the HttpResponse object with the appropriate CSV header. response = HttpResponse(content_type='text/csv') response['Content-Disposition'] = 'attachment; filename="somefilename.csv"' writer = csv.writer(response) writer.writerow([

Reading large images as thumbnails locally via HTML5 filereader

北城余情 提交于 2019-11-30 05:31:13
I am trying to load local images as thumbnails as explained here . My code is below. This works fine for small images. However, when you try load larger images (e.g. 4mb) there is a huge lag. Is there any way to optimize this? Thanks Html <input type="file" id="files" name="files[]" multiple /> <output id="list"></output> Javascript <script> function handleFileSelect(evt) { var files = evt.target.files; // FileList object // Loop through the FileList and render image files as thumbnails. for (var i = 0, f; f = files[i]; i++) { // Only process image files. if (!f.type.match('image.*')) {

Get/set file encoding with javascript's FileReader

浪尽此生 提交于 2019-11-30 04:46:46
I am struggling with the following problem. Using javascript I would like to change the character set of a file content and display this content to the user. I have an input:file form. On change I am reading the content $('#form input:file').change(function(event){ file = this.files[0]; reader = new FileReader(); reader.onload = function(event) { result = event.target.result.replace(/\n/g,'<br />'); $('#filecontents').html(result); }); reader.readAsText(file); }) The file is in Windows-1251. I would like to convert the content of the file to another encoding and after that present it to the

Is it possible to dispatch events on regular objects (not DOM ones)? [duplicate]

我只是一个虾纸丫 提交于 2019-11-30 03:58:31
This question already has an answer here: Can plain Javascript objects have events? 8 answers I just found out that FileReader dispatches events just as if it was a DOM element. Is it? I wonder if it's possible to create an object similar to FileReader, which doesn't have a representation in HTML/XML structure, but can dispatch events? FileReader has methods like addEventHandler because it is defined to implement the EventTarget interface. EventTarget is defined by the DOM Events spec but you don't need to be a DOM object to implement it. window , XMLHttpRequest and FileReader are other

Java基础系列 - try...catch...finally

匆匆过客 提交于 2019-11-30 03:05:35
package com.test6; import java.io.FileReader; import java.io.IOException; /** * try...catch...finally */ public class test5 { public static void main(String[] args) { FileReader fr = null; try { //打开一个不存在的文件 fr = new FileReader("d:\\1.txt"); } catch (Exception e) { e.printStackTrace(); System.out.println("文件打开失败"); } finally { //finally一般都会最后执行,除非一些特殊情况,停电,宕机等 //一般在文件读写,数据库操作,内存操作的时候加上finally进一步处理或释放资源 if (fr != null) { try { fr.close(); } catch (IOException e) { e.printStackTrace(); System.out.println("文件关闭失败"); } } } } }    来源: https://www.cnblogs.com/smartsmile/p/11549182.html