filereader

用文件字符流复制.txt文件

余生颓废 提交于 2020-01-02 20:24:47
用文件字符流复制.txt文件 代码: package cn.tedu.io.file; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class FileCopyText1 { public static void main(String[] args) { //在try块外声明文件字符流对象 FileReader read=null; FileWriter writer=null; try{ //进行对象的初始化 //指明从哪获取数据 read=new FileReader(“D:\1.txt”); //指明往哪存储数据 writer=new FileWriter(“D:\5\4.txt”); //自建缓冲区 char[] cs=new char[1024*1024]; int len=-1;//用于接受获取的字符个数 while ((len=read.read(cs))!=-1){//如果返回值是-1循环结束 //往外写出数据 writer.write(new String(cs,0,len)); //冲刷 writer.flush(); } }catch (IOException e){ }finally { //判断字符输出流对象是否为null

Generate An MD5 Hash of An Image Using HTML5 / JavaScript

泪湿孤枕 提交于 2020-01-02 06:45:08
问题 Using the HTML5 File API and any JavaScript crypto library, how can I generate an MD5 hash of the file? To read the file: var reader = new FileReader(); reader.onload = function(e) { var contents = e.target.result; // What goes here? }; reader.readAsBinaryString(data.files[0]); 回答1: This goes there: var reader = new FileReader(); reader.onload = function(e) { var contents = e.target.result; // This goes here: var hash = CryptoJS.MD5(CryptoJS.enc.Latin1.parse(contents)); }; Be sure you include

HTML5 File API modify file.name

喜你入骨 提交于 2020-01-02 05:40:11
问题 I am trying to modify a file's name if something happens. I have tried doing file.name = file.name + 'extra text'; but it doesn't work. How would I go about changing the file's name once it is uploaded? 回答1: I assume that you are using HTML5 File API to store sandboxed file to local file system. You have to get fileEntry object first if you want to modify an exist file's name: window.webkitRequestFileSystem(window.TEMPORARY, 1024*1024, function(fs){ fs.root.getFile("targetFileFullName",{}

JS - File Reader API get image file size and dimensions

若如初见. 提交于 2020-01-01 10:15:11
问题 Hi i'm using the following code to get the upload image using File Reader API: <script type="text/javascript"> var loadImageFile = (function () { if (window.FileReader) { var oPreviewImg = null, oFReader = new window.FileReader(), rFilter = /^(?:image\/bmp|image\/cis\-cod|image\/gif|image\/ief|image\/jpeg|image\/jpeg|image\/jpeg|image\/pipeg|image\/png|image\/svg\+xml|image\/tiff|image\/x\-cmu\-raster|image\/x\-cmx|image\/x\-icon|image\/x\-portable\-anymap|image\/x\-portable\-bitmap|image\/x\

Java | 文件读写

让人想犯罪 __ 提交于 2019-12-31 13:19:22
import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.*; import java.util.ArrayList; import java.util.List; public class Test { private static final Logger logger = LoggerFactory.getLogger(Test.class); //读取:FileReader //写入:FileWriter //读取内容 public static String readTxt(File file) throws IOException { // 创建文件 //file.createNewFile(); FileReader fileReader = new FileReader(file); String s = ""; // InputStreamReader in = new InputStreamReader(new FileInputStream(file),"UTF-8"); BufferedReader br = new BufferedReader(fileReader); StringBuffer content = new StringBuffer(); while (

How can I solve “Uncaught ReferenceError: blob is not defined”?

空扰寡人 提交于 2019-12-31 06:59:07
问题 Demo and full code like this : https://jsfiddle.net/q93c7Lpf/ It works It uses document.body.appendChild(img); to display the image. And the result like this: <canvas width="660" height="1100" style="width: 600px; height: 1000px;"></canvas> I want to change it to be tag img. So I want to use file reader. I read here html image blob to base64 and Convert blob to base64 And then I try implement it I add this code : var dataURI; var reader = new FileReader(); reader.onload = function(){ // here

java reader vs. stream

心已入冬 提交于 2019-12-31 00:46:12
问题 I was reading about Java I/O and found some interesting areas like streams, readers etc. InputStream input = new FileInputStream("input-file.txt"); int data = input.read(); while(data != -1){ data = input.read(); } I can do the same thing by using Readers as follows: Reader reader = new FileReader("input-file.txt"); int data = reader.read(); while(data != -1){ char dataChar = (char) data; data = reader.read(); } As I know, Streams are used to retrieve input from continuously flowing data. Now

Save content of textarea as plain txt with .csv extension

无人久伴 提交于 2019-12-30 14:08:13
问题 Is there a way to save content as a txt file with a csv file extension using HTML5 ? It shouldn't be a real csv. Something like {type:'text/csv'}; wont work where {type:'text/plain'}; does. 回答1: The a tag's new download property can work to your advantage here. More information. Proof of concept: <!doctype html> <html> <head> <script type="text/javascript"> function save() { var a = document.createElement('a'); with (a) { href='data:text/csv;base64,' + btoa(document.getElementById('csv')

Javascript previews with new FileReader API and DataURLs seem inefficient

点点圈 提交于 2019-12-30 10:02:29
问题 I am using the new FileReader API to preview images before upload. This is done using DataURLs. But DataURLs can be massive if the images are large. This is especially a problem for me as the user may upload multiple images at a time and previewing the bunch has actually slowed my browser considerably and actually crashed chrome a few times. Is there any alternative to using DataURLs for previewing images on the client before upload? 回答1: You can also store data on the client's disk (in

Javascript previews with new FileReader API and DataURLs seem inefficient

筅森魡賤 提交于 2019-12-30 10:01:57
问题 I am using the new FileReader API to preview images before upload. This is done using DataURLs. But DataURLs can be massive if the images are large. This is especially a problem for me as the user may upload multiple images at a time and previewing the bunch has actually slowed my browser considerably and actually crashed chrome a few times. Is there any alternative to using DataURLs for previewing images on the client before upload? 回答1: You can also store data on the client's disk (in