时间:2021-05-23
#mode operand create truncate
#read<
#write> yes yes
#append>> yes
Case 1: Throw an exception if you cannot open the file:
复制代码 代码如下:
use strict;
use warnings;
my $filename = 'data.txt';
open(my $fh, '<:encoding(UTF-8)', $filename)
or die "Could not open file '$filename' with the error $!";
while (my $row = <$fh>) {
chomp $row;
print "$row\n";
}
close($fh);
Case 2: Give a warning if you cannot open the file, but keep running:
复制代码 代码如下:
use strict;
use warnings;
my $filename = 'data.txt';
if (open(my $fh, '<:encoding(UTF-8)', $filename)) {
while (my $row = <$fh>) {
chomp $row;
print "$row\n";
}
close($fh);
} else {
warn "Could not open file '$filename' $!";
}
Case 3: Read one file into array
复制代码 代码如下:
use strict;
use warnings;
my $filename = 'data.txt';
open (FILEIN, "<", $filename)
or die "Could not open file '$filename' with the error $!";
my @FileContents = <FILEIN>;
for my $l (@FileContents){
print "$l\n";
}
close FILEIN;
end
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
java对象输入输出流读写文件的操作实例java支持对对象的读写操作,所操作的对象必须实现Serializable接口。实例代码:packagevo;impor
C++读写文件安全又简洁的简单实例实例代码:#include#include#includeusingnamespacestd;intget_file_cont
本文实例为大家分享了python多线程同步之文件读写控制的具体代码,供大家参考,具体内容如下1、实现文件读写的文件ltz_schedule_times.py#!
复制代码代码如下://////读写INI文件的类。///publicclassINIHelper{//读写INI文件相关。[DllImport("kernel3
本文分享实例代码主要在实现验证文件是否有读写权限问题,具体如下:#Importpythonlibsimportosdefis_writeable(path,ch