() supports two parameters. The first parameter is enabled when Promise is successful, and the second parameter is started when Promise fails. Use. catch () to achieve the same effect. In addition to better readability, the returned Promise object can also be passed at will to continue the chain call, which is quite imaginative.
Continue. then ()So we might as well concatenate more operations (if you want to write a resumable data transfer, let's talk about it later ):
Select All copies and put
Before explaining the specifics of FileInputStream and FileReader in Java, I want to talk about the fundamental differences between InputStream and Reader in Java, and when to use InputStream and reader respectively. In fact, InputStream and reader are abstract classes and do not directly read data from a file or socket. However, the main difference between them is that InputStream is used to read binary data (Byte stream mode, translator note), reade
In the previous article, I introduced the JavaScript operations file, focusing on how to get the Files object. These objects contain the metadata of the files that can be obtained when uploading or dropping them into a browser. With the file, of course, the next step is to read the file.FileReaderFileReaderThe function is simple: Read the data from the file and save it to the JS variable. This API is deliberately designed to XMLHttpRequest be the same
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 (t
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
1, the method of FileReader interfaceThe FileReader interface has 4 methods, 3 of which are used to read the file and the other to interrupt the read. The method does not return a read result, regardless of the success or failure of the read, which is stored in the result property.
Method of FileReader interface
Method Name
Paramete
Remember to do the site, once need to implement a picture uploaded to the server before, preview the function. At that time with the HTML Today, no intention to discover a knowledge point, with the HTML file tag can be implemented before uploading the image preview, it feels great, record! is through the file tag and JS FileReader interface, the selected picture file Call Readasdataurl method, the image d
Transferred from: Http://hi.baidu.com/danghj/item/0ef2e2c4ab95af7489ad9e39Resources:L "Core Java" chapter 12L How to manipulate text files using Java http://java.ccidnet.com/art/3737/20041108/523627_1.htmlWhat kind of FileReader is L? What's the difference with FileInputStream? Http://book.hackbase.com/ask2/ask107572.htmSelf-collation and understanding:Introduction:C language only needs a file*, and unlike C, Java has a series of flow types, the numb
Remember to do the site, once need to implement a picture uploaded to the server before, preview the function. At that time with the HTML Today, no intention to discover a knowledge point, with the HTML file tag can be implemented before uploading the image preview, it feels great, record! is through the file tag and JS FileReader interface, the selected picture file Call Readasdataurl method, the image dat
HTML5 defines FileReader as an important member of the file API for reading files, and the FileReader interface provides a way to read the file and an event model that contains the read result, according to the definition of the system. FileReader is very simple to use, you can create a FileReader object and invoke its
The difference between the FileInputStream class and the FileReader class:The form and parameters of the constructors for two classes are the same, the arguments are file objects, or the string that represents the path, what is the difference between them?? Readers and writers work is only on line based character data, so plain text files.For anything else, you must use Streams.? JDK5 API:FileInputStream is meant for reading streams of raw bytes such
One, Java read and store file data streamJava reads a file, which is actually the process of converting a byte stream in a file into a character flow output to the screenThis involves two classes: InputStreamReader and OutputStreamWriterinputstreamreader: Convert byte streams to character streamOutputStreamWriter: Converting character flow to byte streamInputStreamReader inheriting reader classOutputStreamWriter inheriting writer classSecond, Bufferedreader/
java.ioClass FileReaderJava.lang.Object┗java.io.reader┗java.io.inputstreamreader┗java.io.filereaderAll implemented interfaces: Closeable,readablepublic class FileReader extends InputStreamReaderA handy class for reading character files. The construction method of this class assumes that both the default character encoding and the default byte buffer size are appropriate. To specify these values yourself, you can first construct a inputstreamreader on
Transferred from: http://blog.csdn.net/yaoyuan_difang/article/details/38582697HTML5 defines FileReader as an important member of the file API for reading files, and the FileReader interface provides a way to read the file and an event model that contains the read result, according to the definition of the system.FileReader is very simple to use, you can create a FileRea
Remember to do the site, once need to implement a picture uploaded to the server before, preview the function. At that time with the HTML Today, no intention to discover a knowledge point, with the HTML file tag can be implemented before uploading the image preview, it feels great, record! is through the file tag and JS FileReader interface, the selected picture file Call Readasdataurl method, the image dat
Import java.io.*;
Class Filereaderdemo
{public
static void Main (string[] args) throws IOException
{
//create a file read stream object , associated with a file with the specified name.
//To ensure that the file is already present, if it does not exist, an exception
will occur FileNotFoundException
FileReader fr = new FileReader ("Demo.txt");
Invokes the Read method that reads the stream objec
Differences between fileinputstream and filereader
Core tips: 1) File class introduction File class encapsulates the function of operating the file system on the user's machine. For example, you can use the File class to obtain the last modification time, move the object, or delete or rename the object. In other words, the stream class focuses on the file content, while the file class focuses on the main methods for storing files on disks: (), Last
Html5filereaderUsed to read the file into memory and read the data in the file. The FileReader interface provides an asynchronous API that allows you to asynchronously access the file system in the main thread of the browser and read the data in the file. To current civilian, only ff3.6+ and chrome6.0+ implemented the FileReader interface.1, the method of FileReader
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.