This article mainly introduced the JavaScript writes the TXT and reads the TXT file the method, needs the friend can refer to the next
1. Write
FileSystemObject can translate files into a file stream.
The first step:
Cases:
Copy the code code as follows:
Var fso=new ActiveXObject (Scripting.FileSystemObject);
Create an object that can translate the file into a file stream.
Step two: Use to create a TextStream object
There are three properties inside the parentheses
1. Absolute path to the file
2. The file's constant number is read Only = 1, write only = 2, append =8 and other permissions. (ForReading, ForWriting, or forappending. );
3. A Boolean value that allows new is true instead of false;
Cases:
Copy the code code as follows:
Var f=fso.createtextfile ("C:\a.txt", 2,true);
Step three: Call the TextStream method
1. Write (do not add new line breaks at the end of the write data)
2. WriteLine (to add a new newline character at the end)
3. WriteBlankLines (add one or more empty rows)
Cases:
Copy the code code as follows:
F.writeline ("Wo shi di yi hang");
Fourth Step:
To close the TextStream object:
Example: F.close ();
2. Read
The first step:
Copy the code code as follows:
Var fso=new ActiveXObject (Scripting.FileSystemObject);
Create an object that can translate the file into a file stream.
Step two: Use to create a TextStream object
There are three properties inside the parentheses
4. Absolute path to the file
5. The file's constant number is read Only = 1, write only = 2, append =8 and other permissions. (ForReading, ForWriting, or forappending. );
6. A Boolean value that allows new is true instead of false;
Cases:
Copy the code code as follows:
Var f=fso.opentextfile ("C:\a.txt", 1,true);
Step three: Call the Read method
1. Read (for reading a specified number of characters in a file)
2. ReadLine (reads a whole line, but does not include newline characters)
3. ReadAll (then reads the entire contents of the text file);
Determine if the last line is read
Copy the code code as follows:
while (!f.atendofstream)
{
F.readline ();
}
Fourth Step:
To close the TextStream object:
Example: F.close ();
Here is an example of an HTML open TXT file.
Copy the code code as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title> Hello </title>
<body>
<div id= "AA" ></div>
<script language= "JavaScript" >
var fso, TS, S;
var ForReading = 1;
FSO = new ActiveXObject ("Scripting.FileSystemObject");
TS = fso. OpenTextFile ("D:\\testfile.txt", ForReading);
s = ts. ReadLine ();
document.getElementById ("AA"). Innerhtml=s;
</script>
</body>
Funtion gettest (SRC) {//write wrong, should be function
In addition var src= "C:\Inetpub\wwwroot\myweb\testread.txt"; File path to be written as c:\\. \\
JS is not able to read and write files directly due to security reasons.
If your TXT document is on the server, you can write it through Ajax.
Scripting for reading TXT documents with JavaScript
Here are the freshly baked JavaScript tutorials, the program dog speed look over!
JavaScript Client scripting language
Javascript is a case-sensitive client-side scripting language developed by Netscape's LiveScript to prototype inherited object-based dynamic types, primarily to address server language, such as Perl, legacy speed issues, To provide customers with a smoother browsing effect.
Duqu.htm
<span id=showimport1></span>
<ie:download id= "ODownload1" style= "Behavior:url (#default #download)"/>
<script>
function Ondownloaddone (downdata) {
document.getElementById (' ShowImport1 '). Innerhtml=downdata;
}
Odownload1.startdownload (' Qgwl.txt ', Ondownloaddone)
</script>
</body>
Qgwl.txt
Here is the text content
Javascript is a case-sensitive client-side scripting language developed by Netscape's LiveScript to prototype inherited object-based dynamic types, primarily to address server language, such as Perl, legacy speed issues, To provide customers with a smoother browsing effect.
First, unfortunately, "PHP is the best language", but it is not the most popular language.
At the same time I am sorry to have just in the April tiobe programming language ranking on the list of the various languages:
You're all great, but you can't take the big one.
Before I get started, let me start with the three languages I use: Java, JavaScript, Python.
Java allows me to learn a lot of architecture-level knowledge, which can be referenced in the architecture-related documentation I wrote earlier. Although I don't like the language at all, it's really great.
Python, it's really simple enough that I like to take it to learn a variety of theoretical knowledge, such as recommendation System, Bayesian theorem, natural language processing and so on.
JavaScript, see below.
Visualization of data
In some of the books I read in the past, mainly in the processing as a visual language-it started in 2001, it was originally created for artists and designers, and later became a comprehensive design and prototyping tool that can be used to create complex data visualization areas.
Processing was brought into the web to produce a processing.js, and there was d3.js.
Of course, there are plotly, leaflet, Sigma JS and so on tools.
Mobile Applications: Cordova
Then there's PhoneGap (today's Cordova), bringing WebView to the mobile app and bringing JavaScript to the mobile app.
With Cordova, you can let us develop multi-platform publishing at once. We also mention Ionic as a leader in hybrid applications:
Mobile Applications: React Native
Now that we have mentioned Cordova, we should also talk about react Native. Also developed several times to run:
Although it has a lot of pits, but it is worth looking forward to.
Service side: node. js
It was V8 's performance that brought JavaScript to a new height, so that node. JS was born-the front end, the backend can be used JavaScript, a JavaScript full stack era.
MongoDB as a database, express as server-side MVC, they can provide a restful service, then plus the angular.js of the MVVM framework, you know what I'm talking about!
Desktop applications: Nw.js and Electron
Nw.js is run based on Chromium and node. js, and they allow us to make desktop applications with HTML and JavaScript. Besides Nw.js and the Electron,atom editor of the recent fire.
Unlike Cordova's multi-platform build multi-version, electron can build applications on multiple platforms on a single platform. That is, we can package the Linux and Windows apps on Mac OS without having to compile windows again.
To the desktop side, keeping the desktop and the Web consistent. The most successful case is the slack, which is valued at $3 billion:
So, if you use the desktop side of the slack will be very card.
Full Platform Application
I once wrote a code to build mobile, desktop, Web full platform application, running ionic on Eletcron, that means unlimited possibilities.
It's good to use the web to get things done with web development.
Game
The moment that WebGL was brought into the browser, it was decided that it was a new world.
Let's forget about compiling, starting updates, plug-ins, and so on, and we can also run a direct development.
Vr
If you've seen the previous article, "JavaScript in the VR world," you'll be more impressed with the content.
The main idea is to use WebView to render VR perspectives:
and each browser manufacturers in the promotion of Webvr for virtual reality device display to provide support.
Ar
While most AR applications may be a bit far away from us, the closest thing to us is leap motion--, which can be entered using palm and finger movements, but without touching or touching the hand.
In the same vein, the data from the sensor is read, and the gesture is left to the browser to handle. For details, refer to my previous writing: "Leap Motion JavaScript Development gesture Control Basics"
Hardware
Earlier I saw that Arduino encapsulated the API in a DSL when it was compiled. The NODEMCU is built with the support of the Lua language, allowing the beginning to start with Lua. And Tessel was born to provide JavaScript runtime environment, we write need to write good JavaScript can be run on it.
Tessel 2 is a relatively high-configuration hardware, but low-matching it?
Samsung designed the Jerryscript engine to run on less than 64KB of memory, and all the code could be stored on less than 200KB of read-only storage (ROM).
Think about the future is beautiful.
Internet of Things
And so on, the above Samsung is iot.js, which means it can already be used in the Internet of things, why there are applications here? I just want to mention this a little bit:
It's all about node. JS's application in the Web, and the big difference between the internet of things and the web is that the IoT can use a variety of different protocols that require the support of node. js.
Therefore, if we need to start the Web version, mobile app, then we naturally need it as a background.
Operating System interface
Although better machines bring better performance, it is clear that the demand for native applications is not so strong. The Firefox OS has been lost in the mobile operating system, but this operation has been brought to the IoT area:
This means that we can use JavaScript to develop the interface of the operating system.
What else do you think JavaScript can do?
Brother Coat
Annual
Wang Xiaoyuan
Handsome Total
The embarrassing pill
God Bless
Rogue three gold
Picasso
Wang Mian
Wind small Zheng
Brother Lee
God Bless
? God bless
How JavaScript writes to TXT and reads txt files