How to read and write binary files in jscript_javascript skills
本文实例讲述了jscript读写二进制文件的方法。分享给大家供大家参考。具体实现方法如下:
var bin = new Array(256); for(var i=0;i<256;i++){ bin[i]=String.fromCharCode(i); } function TestWrite(){ var Stream = new ActiveXObject("ADODB.Stream"); var adTypeBinary=1,adTypeText=2; Stream.Type = adTypeText; Stream.CharSet = "iso-8859-1"; Stream.Open(); //Stream.WriteText("\x00\x01\x02\xff\xff"); for(var i=0;i<256;i++){ Stream.WriteText(String.fromCharCode(i)); //Stream.WriteText(bin[i]); } Stream.SaveToFile("c:\\windows\\temp\\test.bin", 2); Stream.Close(); Stream = null; } function BinaryFile(filepath){ var adTypeBinary=1,adTypeText=2; var adSaveCreateNotExist=1,adSaveCreateOverWrite=2; var adReadAll=-1,adReadLine=-2; this.path=filepath; this.WriteAll = function(content){ var Stream = new ActiveXObject("ADODB.Stream"); Stream.Type = adTypeText; Stream.CharSet = "iso-8859-1"; Stream.Open(); Stream.WriteText(content); Stream.SaveToFile(this.path, adSaveCreateOverWrite); Stream.Close(); Stream = null; } this.ReadAll = function(){ var Stream = new ActiveXObject("ADODB.Stream"); Stream.Type = adTypeText; Stream.CharSet = "iso-8859-1"; Stream.Open(); Stream.LoadFromFile(this.path); var content = Stream.ReadText(adReadAll); Stream.Close(); Stream = null; return content; } }
用法示例如下:
var crFolder = 'C:/Temp/cr' var bf1=new BinaryFile(crFolder+"/PCDV0026.JPG"); var bf2=new BinaryFile(crFolder+"/PCDV0026_.JPG"); bf2.WriteAll(bf1.ReadAll());
希望本文所述对大家的javascript程序设计有所帮助。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP is a language widely used in web development. It provides many functions and methods for processing files. In PHP, we can use binary mode to read and write files. This method can improve the efficiency of file operations, especially when processing binary files. In this article, we will explore binary file reading and writing operations in PHP and how to use this method to process binary files. What is a binary file? Binary files refer to files represented by pure binary, and their contents may contain different encoded character sets.

How to read and write binary files in C++: Write binary files: Use the std::ofstream class and set the output mode to std::ios::binary. Read binary files: Use the std::ifstream class and set the input mode to std::ios::binary.

How to use PHP to implement data caching and read-write functions. Caching is an important way to improve system performance. Through caching, frequently used data can be stored in memory to increase the reading speed of data. In PHP, we can use various methods to implement data caching and reading and writing functions. This article will introduce two common methods: using file caching and using memory caching. 1. Use file caching. File caching stores data in files for subsequent reading. The following is a sample code that uses file caching to read and write data:

Concept fio, also known as FlexibleIOTester, is an application written by JensAxboe. Jens is the maintainer of blockIOsubsystem in LinuxKernel. FIO is a tool used to test network file system and disk performance. It is often used to verify machine models and compare file system performance. It automatically sends fio commands to a list of cluster machines and collects IOPS for small files and throughput data for large files. rw=[mode]rwmixwrite=30 In mixed read and write mode, writing accounts for 30% moderead sequential read write sequential write readwrite sequential mixed read and write randwrite random write r

File System APIThe internal principles of Java file operations are closely related to the file system API of the operating system. In Java, file operations are provided by the java.nio.file module in the java.NIO package. This module provides an encapsulation of the file system API, allowing Java developers to use a unified API to perform file operations on different operating systems. File Object When a Java program needs to access a file, it first needs to create a java.nio.file.Path object. The Path object represents a path in the file system, which can be an absolute path or a relative path. Once the Path object is created, you can use it to get various properties of the file, such as the name

How to use GitLab for binary file management and archiving GitLab is an open source version control system that uses Git as a version control tool and provides a visual web interface. Many people use GitLab to manage and archive source code, but some people may be confused when it comes to the management and archiving of binary files. This article will introduce how to effectively manage and archive binary files in GitLab, and provide some specific code examples. Create a new GitLab project first, in

Decrypting the reading and writing methods of processing DBF files in Java DBF (dBaseFile) is a common database file format that is usually used to store tabular data. In Java programs, processing the reading and writing of DBF files is a relatively common requirement. This article will introduce how to use Java to decrypt this process and provide specific code examples. 1. Reading DBF files In Java, reading DBF files usually requires the use of third-party libraries, such as the dbfread library. First, you need to configure the project

A file is a collection of records (or) a place on a hard disk where data is permanently stored. There are two types of file languages in File Type C as follows - Text file Binary file Text file It contains letters and numbers that are easily understandable by humans. Errors in text files can be eliminated under the following conditions: In text files, text and characters are stored one character per byte. For example the integer value 4567 will occupy 2 bytes in memory but 5 bytes in the text file. Data formats are usually row-oriented. Here, each line is a separate command. Binary file contains 1's and 0's and is easily understood by computers. Errors in binary files can corrupt the file and are difficult to detect. In binary file, integer value 1245 will occupy 2 bytes in memory and file
