Perl中读取含有中文的路径 或 含有中文的文件名
来源:互联网 发布:卓易云软件下载 编辑:程序博客网 时间:2024/05/18 03:45
File name is encoded in UTF-16LE on Windows. Windows offers two interfaces to access the file by name. The first one is the regular char inteface, which requires file name represented in a native encoding such as cp936 for Simplified Chinese. The second one is the wide char interface, which allows file name expressed in UTF-16. Perl's built-in open() function doesn't use the wide char interface, so the non-English file name must be encoded in the local encoding before passing to open(). The Encode::Locale helps Perl programmer to determine the native encoding to use, here is an example usage:
- #!/usr/bin/perl -w
- use strict;
- use utf8;
- use Encode::Locale qw($ENCODING_LOCALE_FS);
- use Encode;
- printf "%s\n", $ENCODING_LOCALE_FS;
- my $f1 = encode(locale_fs => '数据库日志.lg');
- open(my $fh, "<", $f1) or die "Can't open file $f1 due to: $!";
- while(<$fh>) {
- print;
- }
- close $fh;
#!/usr/bin/perl -wuse strict;use utf8;use Encode::Locale qw($ENCODING_LOCALE_FS);use Encode;printf "%s\n", $ENCODING_LOCALE_FS;my $f1 = encode(locale_fs => '数据库日志.lg');open(my $fh, "<", $f1) or die "Can't open file $f1 due to: $!";while(<$fh>) { print;}close $fh;
Python seems behave similar to Perl. Java is capable of taking file name represented in both unicode and native encoding.
0 0
- Perl中读取含有中文的路径 或 含有中文的文件名
- android 路径中含有中文的解决方法
- URL路径中含有中文
- 超链接的路径中含有中文页面无法访问的问题。
- java工程中的路径中含有中文的解决方法
- Java读取文件中含有中文的解决办法
- Java读取文件中含有中文的解决办法
- Java读取文件中含有中文的解决办法
- Java读取文件中含有中文的解决办法
- Java读取文件中含有中文的解决办法
- Java读取文件中含有中文的解决办法
- Java读取文件中含有中文的解决办法
- python3如何读取含有中文的文本
- java中不支持系统路径中含有中文或空格
- Python读取含有中文路径文件
- 链接中含有中文参数的问题
- iOS 的url中含有中文解决方法
- QNetworkAccessManager 实现FTP上传功能,解决 文件名是中文,QUrl含有中文路径 不能上传的问题
- Android 探究 LayoutInflater setFactory
- 基于机器学习的数字识别服务端
- 设计模式之组合模式
- Android Studio断点调试
- 天翼杯大数据算法应用大赛
- Perl中读取含有中文的路径 或 含有中文的文件名
- 如何处理List of devices attached为空的问题
- kettle读文件
- 正则表达式匹配规则
- 100. Same Tree
- Hibernate(三)
- 朴素贝叶斯之MapReduce版
- 创建XMLHttpRequest对象
- 解决mac下sublime中文乱码