Home Web Front-end JS Tutorial Knowledge about file reading

Knowledge about file reading

Jul 18, 2017 pm 04:15 PM
Knowledge

Recently, a colleague asked me if js can read local files;

I remembered the article I saw about js reading local files before, and then I wrote a demo myself.

ps: This is a bit like Java's IO stream, but there are differences.

Here are some steps I summarized:

1. Get the file object
var file=document.querySelector('input');
2. Set change Event
file.onchange=function(){
   3. Get file resources
   var list=this.files;
   4. Create reader
  var reader=new FileReader() ;
5. Start reading the file
The readAsDataURL() method returns a file path
The readAsText() method returns a file content (string)
reader.readAsDataURL(list[0]);
              Get the result after the file reading is completed
                                                                                                                                                                                      are are to be obtained and the result is obtained after the file is read, reader.onload=function(){
##    }
}

In the event, you can look at console.dir(this) in the background; pay attention to the two methods of reading files ①readAsDataURL() method returns a file path ②readAsText() The method returns a file content (string);

The above is the detailed content of Knowledge about file reading. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Let you learn about the shocking win10x system knowledge Let you learn about the shocking win10x system knowledge Jul 14, 2023 am 11:29 AM

Recently, the latest image download of win10X system has been leaked on the Internet. Different from the common ISO, this image is in .ffu format and can currently only be used for Surface Pro7 experience. Although many friends can’t experience it, you can still read the relevant content of the evaluation and enjoy it. Let’s take a look at the latest evaluation of the win10x system! The latest evaluation of the win10x system 1. The biggest difference between Win10X and Win10 first appears after booting up. Buttons are placed in the center of the taskbar. In addition to pinned applications, the taskbar can also display recently launched applications, similar to Android and iOS phones. 2. Another thing is that the “Start” menu of the new system does not support file

Let's talk about knowledge extraction. Have you learned it? Let's talk about knowledge extraction. Have you learned it? Nov 13, 2023 pm 08:13 PM

1. Introduction Knowledge extraction usually refers to mining structured information from unstructured text, such as tags and phrases containing rich semantic information. This is widely used in the industry in scenarios such as content understanding and product understanding. By extracting valuable tags from user-generated text information and applying them to content or products, knowledge extraction is usually accompanied by the classification of the extracted tags or phrases. , is usually modeled as a named entity recognition task. The general named entity recognition task is to identify named entity components and classify the components into place names, person names, organization names and other types; domain-related tag word extraction identifies and divides tag words into Field-defined categories, such as series (Air Force One, Sonic 9), brand (Nike, Li Ning), type (shoes, clothing, digital), style (

Understanding Golang: essential knowledge for developers Understanding Golang: essential knowledge for developers Feb 23, 2024 am 10:51 AM

Golang, also known as Go language, is an open source programming language developed by Google. Since its release in 2007, Golang has gradually emerged in the field of software development and has been favored by more and more developers. As a statically typed, compiled language, Golang has many advantages, such as efficient concurrent processing capabilities, concise syntax, and powerful tool support, making it have broad application prospects in cloud computing, big data processing, network programming, etc. . This article will introduce the basic concepts of Golang,

How does a chatbot answer questions through a knowledge graph? How does a chatbot answer questions through a knowledge graph? Apr 17, 2023 am 09:13 AM

Preface In 1950, Turing published the landmark paper "Computing Machinery and Intelligence" (Computing Machinery and Intelligence), proposing a famous judgment principle about robots - the Turing test, also known as the Turing judgment, which states that if the first If the three cannot distinguish the difference between the responses of humans and AI machines, it can be concluded that the machine has artificial intelligence. In 2008, the AI ​​butler Jarvis in Marvel's "Iron Man" let people know how AI can accurately help humans (Tony) solve various matters thrown at them... Figure 1: AI butler Jarvis ( Picture source: Internet) In early 2023, Chat, a free chat robot that broke out in the technology world in a 2C way, became popular.

Understanding Linux Server Security: Essential Knowledge and Skills Understanding Linux Server Security: Essential Knowledge and Skills Sep 09, 2023 pm 02:55 PM

Understanding Linux Server Security: Essential Knowledge and Skills With the continuous development of the Internet, Linux servers are increasingly used in various fields. However, since servers store a large amount of sensitive data, their security issues have also become the focus of attention. This article will introduce some essential Linux server security knowledge and skills to help you protect your server from attacks. Updating and Maintaining Operating Systems and Software Timely updating of operating systems and software is an important part of keeping your server secure. Because every operating system and software

Learn more about jQuery sibling nodes Learn more about jQuery sibling nodes Feb 27, 2024 pm 06:51 PM

There is no doubt that jQuery is one of the most used JavaScript libraries in front-end development, providing a concise and powerful way to manipulate HTML documents. In jQuery, sibling nodes are elements that have the same parent element as the specified element. A deep understanding of jQuery sibling nodes is crucial for front-end developers. This article will introduce how to use jQuery to operate sibling nodes, and attach specific code examples. 1. To find sibling nodes in jQuery, we can pass

Master the key knowledge and practical skills of HTML global attributes Master the key knowledge and practical skills of HTML global attributes Jan 06, 2024 am 08:40 AM

Essential knowledge and practical skills for learning the global attributes of HTML HTML (HyperTextMarkupLanguage) is a markup language used to create the structure of web pages. When building web pages, we often need to use various tags and attributes to define the appearance and behavior of the page. Among all HTML attributes, global attributes are a very important type of attributes. They can be applied to all HTML tags, providing web developers with powerful flexibility and customization capabilities. Learning and using HTML

Must-learn JSP built-in object knowledge: Understand what are the commonly used built-in objects in JSP Must-learn JSP built-in object knowledge: Understand what are the commonly used built-in objects in JSP Jan 10, 2024 pm 04:39 PM

Necessary knowledge for learning JSP built-in objects: To master the built-in objects in jsp, you need specific code examples. JSP (JavaServerPages) is a dynamic web page development technology. Its advantage is that it combines dynamic programming languages ​​​​(such as Java) and static pages. Features. In JSP, built-in objects play an important role to facilitate developers for data processing and page rendering. This article will introduce some commonly used JSP built-in objects and provide specific code examples to deepen understanding. request pair

See all articles