ファイルの読み書き

C言語

Perl

#!/usr/bin/perl

open(FH, "<" . $ARGV[0]) or die("open");

while( $line = <FH>)
{
        print $line;
}

close(FH);
$ perl test.pl aaa

Python

>>> f = open('aaa', 'r')
>>> f.read()
'aaa\nbbb\nccc\n\n'
>>> f.close()
>>> f = open('aaa', 'r')
>>> f.readline()
'aaa\n'
>>> f.readline()
'bbb\n'
>>> f.readline()
'ccc\n'
>>> f.readline()
'\n'
>>> f.readline()
''
>>> f.readline()
''
>>> f = open('aaa', 'r')
>>> f.readlines()
['aaa\n', 'bbb\n', 'ccc\n', '\n']
>>>
>>> f = open('aaa', 'r')
>>> for line in f:
...     print line,
...
aaa
bbb
ccc

>>>

Ruby


Front page   Diff Backup Reload   List of pages Search Recent changes   Help   RSS of recent changes
Last-modified: Tue, 07 Jun 2011 20:32:11 JST (2177d)