【发布时间】:2019-07-01 17:59:27
【问题描述】:
我正在从 java 程序创建一个 .bat 文件:
final OutputStreamWriter fop = new OutputStreamWriter( new FileOutputStream( "test.bat" ), Charset.forName( "UTF8" ) );
并使用Runtime.getRuntime().exec(); 执行它
在目录中 (C:\usr\testdir)
@echo off
cd C:\usr\testdir
echo "hello"
上面的bat文件执行成功。
但是当我更改包含德语变音符号的目录路径时,它给了我错误。:
The system cannot find the path specified
其中 dir 路径 (C:\usr\wÖrkingÄÜÖ) 和 ./bat 将是相同的:
@echo off
cd C:\usr\wÖrkingÄÜÖ
echo "hello"
所以问题是包含变音符号的路径。在 Google 帮助后,我在 bat 文件顶部添加 chcp 652001 以更改 pageCode,但问题仍然存在。任何人都可以帮助我我所缺少的吗?
【问题讨论】:
-
也许你可以试试
Cp1252编码而不是UTF8。 -
尝试使用 :chcp 1252>nul 。对 path/to/dir/ 的错误更改是不可执行的
-
嗯,我的意思是像
Charset.forName("Windows-1252")。 docs.oracle.com/javase/7/docs/technotes/guides/intl/…
标签: java batch-file character-encoding