bat 文件读取乱码问题

使用 for 循环

type file1.txt > file2.txt

文件读取后可能会出现乱码,需要在 bat 文件中设置

chcp 65001 

表示将批处理设置为 utf-8 编码,这样在生成文件和读取文件时,就会自动设置为 utf-8

code page 列表:

https://docs.microsoft.com/en-us/windows/desktop/intl/code-page-identifiers

提供一个简单的例子:

  

@echo off & setlocal enabledelayedexpansion
chcp 65001

for /f "tokens=*" %%i in (context.txt) do (
    setlocal disabledelayedexpansion
    set line=%%i
    setlocal enabledelayedexpansion
    echo !line!    
)
原文地址:https://www.cnblogs.com/ryanzheng/p/9473223.html