Java Tour (24)--i/o stream, character stream, filewriter,ioexception, file continuation, FileReader, small exercise
The Java tour is also written more than 20, we finally reached the I/O today. If you beginner, do not understand the IO stream, you can look at slowly after the trip, but you work for a while you will find that the flow of the use of the scene and the technical point is very tough, we are bound to grasp this knowledge point, if
Yes:Domstring, Document, FormData, Blob, File, ArrayBufferLook at Zhang's blog. http://www.zhangxinxu.com/wordpress/2013/10/understand-domstring-document-formdata-blob-file-arraybuffer/Where the FileReader interface does some preparation:1, the method of FileReader interfaceThe FileReader interface has 4 methods, 3 of which are used to read the file and the other
Local Link for uploading images -- FileReader,Reference website
FileReader-Web API | MDNDEMOIntroduction
With the FileReader object, web applications can asynchronously read files (or raw data buffering) stored on users' computers, you can use a File object or Blob Object to specify the File or data to be processed. the File object can be the FileList object retu
Import java. Io .*;Public class filereader {// read a file and display it
Public static void main (string ARGs []){String name = "te.txt"; // C: // te.txtFile Ss = new file (name );Try{Filereader A = new filereader (SS );Bufferedreader BR = new bufferedreader ();String S = Br. Readline ();While (s! = NULL) // The value is not null.{System. Out. println ("read" +
Using HTML5 's FileReader can realize the multimedia file preview function, the code is as follows:The code works as follows:The FileReader interface has the following methods:
Method Name
Parameters
Description
Readasbinarystring
File
To read a file as a binary encoding
Readastext
File,[encoding]
To read a file as text
Java FileReader and FileWriter
Overview
Character streams are IO streams that can read characters directly
Character stream to read the characters, it is necessary to read the byte data first, then convert to the character. If you want to write a character, you need to convert the character to byte and write
Whether a character stream can copy files that are not plain text. Files that are not text-less can be copied because the bytes are converted t
= "showfiles ();" /> h4>Select the file as Follows:h4> imgsrc=""ID= "img1" />Div>Js://reading a picture instancevarFilebox = document.getElementById (' file ');functionshowfiles () {//get an array of selected files varFileList =filebox.files; for(vari = 0; I ) { varFile =filelist[i]; //Picture Type verification the second way if(/image\/\w+/. Test (file.type)) readFile (file); ElseConsole.log (file.name+ ': not pictures '); }}/
methods are not the same. Using Httpfox to crawl the requested data, you will find that the content of the upload is not the above said by boundary separated, but directly to the contents of the file post out, and the file name, size and other related information on the head of the file. such as 163 mailbox:
POST Data:
This is a text
Headers:
Mail-upload-name:content.txtMail-upload-size:15
It can be speculated that they should read the contents of the input file directly, and then post it
The client code is found online and is modified to. NET code.Get pictures using HTML5 FileReader and upload them asynchronously to the server (not iframe) For= "img" title= "jpg,gif,png" > Please select Picture Service-Side code:public void ProcessRequest (HttpContext context){if (context. Request["img"] = NULL)//Generate check code{String imgname = context. request["Imgname"];String imgextention = System.IO.Path.GetExtension (imgname). ToLower ();if
Before the file upload, we always want to preview the contents of the file, or the image, HTML5 in the FileReader just provide 2 ways, you can not upload files in the case, preview the contents of the file.Image preview: Readasdataurl (file);File preview: Readastext (); (must ensure that the file encoding format is the same as the Code encoding format, preview Chinese will not garbled)DOCTYPE HTML>HTMLLang= "en">Head> MetaCharSet= "UTF-8"> title>HTM
public class Filereaderdemo {public static void main (string[] args) {try {filereader fr=new filereader ("Abc.txt");//int Ch =fr.read ();//if (ch!=-1) {//system.out.println (char) ch),//}int ch=0;//read characters, if the end of the stream is reached, then return -1while ((Ch=fr.read ())!=-1) {System.out.println ((char) ch);}} catch (Exception e) {e.printstacktrace ();}}This article from "Promise always att
Implement drag-and-drop images, display pictures and manipulate sizes before uploading to the serverUsing HTML5DragEnterDragOverDragLeaveDropIn the realization of the picture display, the use of FileReader this classvar files=event.datatransfer.files;//get a drag-and-drop picture collectionFilereader.readasdataurl (Files[i]);Using This.result Show pictures to pageTo get the image size, you need to re-instantiate an Image object:var img = new Image ();
Baidu Experience Version number: How to generate Data Url with HTML5 FileReaderPrevious article: Writing the data URL Generation tool in Visual Studio 2010 C # versionToday with HTML5 FileReader implementation of the data URL Generation tool, the code bar:Finally: HTML5 FileReader Implementation of the Data URL generation tool
One.After you have finished writing, read it. Now the object being explained has changed from FileWriter to FileReader, from output to input.The explanation of Io flow is always around the character stream, and the foothold is also the two specific subclass object in the character flow.The reader object's methods are described in various ways of reading.The read exception is described.Write the program completely and the results are as follows. When r
Java Filereader/filewriter Read and write letters and numbers is no problem, but read and write Chinese characters are garbled. Record, then find the solution and then fill it up.public static void Main (string[] args) {FileReader FR = null;FileWriter FW = NULL;try {int a = 0;FR = new FileReader ("C:/a.txt");//Read targetFW = new FileWriter ("C:/b.txt");//write t
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.