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" +
Use FileReader to encode the file as Base64 and then upload it through AJAX,
You cannot directly upload files using AJAX. Generally, a new iframe is used to complete the form submission process in order to achieve asynchronous file upload.This can achieve better browser compatibility, but the amount of code will be relatively large, even if the file upload plug-in is used, such as plupload.
How can we achieve flexibility? Just treat a file as a common
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
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
HTML5 file fields + FileReader read files in segments and upload them to the server,
Note: the file cannot be too large to be uploaded using Ajax. It is better to be smaller than 300 or 400 mb, because too many consecutive Ajax requests will cause the background to crash and the data obtained from InputStream will be blank, especially in the Google browser testing process.
1. Read the file Blob in simple segments and upload the file to the server usin
About the file API here is not explained in detail, small partners to their own Niang it, we will use the file handle to read the file content, this is achieved through the FileReader, through the FileReader interface, we can asynchronously load the contents of the file into memory, give a JS variable.
Copy Code code as follows:
function getimgsrc (target, callback) {
if (window.
= "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 '); }}//read image content as Dataurl//Reader.readas
FileReaderFileReader is primarily used to read the contents of a file into memory, and through a series of asynchronous interfaces, local files can be accessed in the main thread.Method
method Definition
Description
Abort (): void
Terminating file read operations
Readasarraybuffer (file): void
Asynchronously reads the contents of a file in bytes, and the result is represented by a Arraybuffer object
Readasbinarys
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
FileReader is similar to XMLHttpRequest, but it is used to read files from the file system, providing different ways to read file data:1, Readastext2, Readasdataurl3, Readasbinarystring4, ReadasarraybufferThe process of reading is asynchronous, some events can be monitored, progress,error,load, etc.The progress event does not trigger once in 50 milliseconds, and there is a lengthcomputable,loaded,total attribute that allows you to see how much data is
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.