filereader

Java自学-I/O 缓存流

泄露秘密 提交于 2019-12-02 18:46:18
Java 缓存流BufferedReader,PrintWriter 以介质是硬盘为例, 字节流和字符流的弊端 : 在每一次读写的时候,都会访问硬盘。 如果读写的频率比较高的时候,其性能表现不佳。 为了解决以上弊端,采用缓存流。 缓存流在读取的时候, 会一次性读较多的数据到缓存中 ,以后每一次的读取,都是在缓存中访问,直到缓存中的数据读取完毕,再到硬盘中读取。 就好比吃饭, 不用缓存就是每吃一口都到锅里去铲 。 用缓存就是先把饭盛到碗里 ,碗里的吃完了,再到锅里去铲 缓存流在写入数据的时候,会先把数据写入到缓存区,直到缓存区 达到一定的量 ,才把这些数据, 一起写入到硬盘中去 。按照这种操作模式,就不会像字节流,字符流那样 每写一个字节都访问硬盘 ,从而减少了IO操作 示例 1 : 使用缓存流读取数据 缓存字符输入流 BufferedReader 可以一次读取一行数据 package stream; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; public class TestStream { public static void main(String[] args) { // 准备文件lol.txt其中的内容是

前端图片上传那些事儿

家住魔仙堡 提交于 2019-12-02 18:10:24
本文讲的图片上传,主要是针对上传头像的。大家都知道,上传头像一般都会分成以下 4 个步骤: 选择图片 -> 预览图片 -> 裁剪图片 -> 上传图片 接下来,就详细的介绍每个步骤具体实现。 选择图片 选择图片有什么好讲的呢?不就一个 input[type=file] ,然后点击就可以了吗?确实是这样的,但是,我们想要做得更加的友好一些,比如需要过滤掉非图片文件, 或只允许从摄像头拍照获取图片等,还是需要进行一些简单配置的。 下面就先来看看最简单的选择图片: <input type="file" /> 这时候,点击这个 input , 在 iOS 手机的显示如下: 其中的 “浏览” 选项,可以查看到非图片类型的文件,这并不是我们想要的结果,毕竟我们只想要图片类型。可以通过 accept 属性来实现,如下: <input type="file" accept="image/*"> 这样就可以过滤掉非图片类型了。但是图片的类型可能也太多了, 有些可能服务器不支持,所以,如果想保守一些,只允许 jpg 和 png 类型,可以写成这样: <input type="file" accept="image/jpg, image/jpeg, image/png"> 或: <input type="file" accept=".jpg, .jpeg, .png"> OK, 过滤非图片的需求搞定了

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

狂风中的少年 提交于 2019-12-02 16:51:55
[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, statistics, English, Anatomy" "Tan", "Betty", "F", "High School", "Algebra I, chem I, English 101" "Han", "Anna", "F", "University", "PHY 3, Calc 2, anatomy I, spanish 101" "Hawk", "Alan", "M", "University", "English 101, chem I" I eventually need do parse it and output something like: Chem I: 3 (number of people taking

Counting distinct words with Threads

天大地大妈咪最大 提交于 2019-12-02 15:10:06
问题 The objective is to count distinct words from a file. UPDATE: Previous Code was successfully finished. Now I have to do the same but using threads (Oh man, I hate them...) and in addition I want to make it with semaphores for better flow. Code contains some extra stuff left out from previous attempts, I'm trying to figure out what can be used.. I can read one word at a time but mostly I get a "null" in the container. So until I get anything from the container all the time I can't test the

Java自学-I/O 中文问题

痴心易碎 提交于 2019-12-02 15:03:27
Java中的编码中文问题 步骤 1 : 编码概念 计算机存放数据只能存放数字,所有的字符都会被转换为不同的数字。 就像一个棋盘一样,不同的字,处于不同的位置,而不同的位置,有不同的数字编号。 有的棋盘很小,只能放数字和英文 有的大一点,还能放中文 有的“足够”大,能够放下世界人民所使用的所有文字和符号 如图所示,英文字符 A 能够放在所有的棋盘里,而且位置都差不多 中文字符, 中文字符 中 能够放在后两种棋盘里,并且位置不一样,而且在小的那个棋盘里,就放不下中文 步骤 2 : 常见编码 工作后经常接触的编码方式有如下几种: ISO-8859-1 ASCII 数字和西欧字母 GBK GB2312 BIG5 中文 UNICODE (统一码,万国码) 其中 ISO-8859-1 包含 ASCII GB2312 是简体中文,BIG5是繁体中文,GBK同时包含简体和繁体以及日文。 UNICODE 包括了所有的文字,无论中文,英文,藏文,法文,世界所有的文字都包含其中 步骤 3 : UNICODE和UTF 根据前面的学习,我们了解到不同的编码方式对应不同的 棋盘 ,而UNICODE因为要存放所有的数据,那么它的棋盘是最大的。 不仅如此,棋盘里每个数字都是很长的(4个字节),因为不仅要表示字母,还要表示汉字等。 如果完全按照UNICODE的方式来存储数据,就会有很大的浪费。 比如在ISO

Getting the result object of FileReader()

ε祈祈猫儿з 提交于 2019-12-02 14:12:24
is there any way i can fetch the result object of a FileReader() without getting through a function ? i have made a sample code below: HTML <br /> <br /> <br /> <div> </div> JS var code = "lorem ipsum"; $("input[type='file']").change(function() { var upload = this.files[0]; var reader = new FileReader(); reader.onload = function() { code = reader.result; $("div").append("<label>this should appear first: " + code + "</label> <br />"); }; reader.readAsDataURL(upload); $("div").append("<label> this should appear last: " + code + "</label> <br />"); }); the problem with this code is that the

Java自学-I/O 字符流

▼魔方 西西 提交于 2019-12-02 10:55:44
Java的字符流 Reader Writer Reader字符输入流 Writer字符输出流 专门用于字符的形式读取和写入数据 步骤 1 : 使用字符流读取文件 FileReader 是Reader子类,以FileReader 为例进行文件读取 package stream; import java.io.File; import java.io.FileReader; import java.io.IOException; public class TestStream { public static void main(String[] args) { // 准备文件lol.txt其中的内容是AB File f = new File("d:/lol.txt"); // 创建基于文件的Reader try (FileReader fr = new FileReader(f)) { // 创建字符数组,其长度就是文件的长度 char[] all = new char[(int) f.length()]; // 以字符流的形式读取文件所有内容 fr.read(all); for (char b : all) { // 打印出来是A B System.out.println(b); } } catch (IOException e) { // TODO Auto-generated

Convert local image blob to base64, in PHP

会有一股神秘感。 提交于 2019-12-02 10:37:23
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 great. However, I'm running into file size issues. Specifically a 1000px x 1000px (402KB) test image. The

Javascript, spliced FileReader for large files with Promises, how?

半城伤御伤魂 提交于 2019-12-02 09:51:56
I'm trying to use FileReader to read several files sequentially using promises for that. The problem is that I need to divide the reading operations in several chunks to make them doable. By doing so, I lose the Promise chain. This is what happen in the following code, where I get the console log here , then catched (meaning I've lost the chain), then inside and then finished . Somehow the Promise in upload is not respected. Here it is the code (please go to the last EDIT, I keep the original text nonetheless) var reader = new FileReader(); reader.onloadend = function(e) { if (e.target

What do I have to add at the beginning of this loop?

别等时光非礼了梦想. 提交于 2019-12-02 08:59:01
how I can read the following files using the for loop: (can the loop ignore the characters in filenames?) abc-1.TXT cde-2.TXT ser-3.TXT wsz-4.TXT aqz-5.TXT iop-6.TXT What do I have to add at the beginning of this loop ?? for i = 1:1:6 nom_fichier = strcat(['MyFile\.......' num2str(i) '.TXT']); You can avoid constructing the filenames by using the DIR command. For instance: myfiles = dir('*.txt'); for i = 1:length(myfiles) nom_fichier = myfiles(i).name; ...do processing here... end First of all, why would you use strcat here? This is, by itself, a SINGLE string. All concatenation has already